【发布时间】:2021-06-02 10:29:52
【问题描述】:
我有一个使用 NLog 的 .NET Core 3.1 服务。 这是我的 NLog.config 代码:
<?xml version="1.0" ?>
<nlog autoReload="true"
xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="AsyncInformation" xsi:type="AsyncWrapper">
<target type="WebService"
name="ws"
url="https://log-api.com/log/v1"
protocol="JsonPost">
<parameter name="">
<layout xsi:type="newrelic-jsonlayout">
<attribute name="time" layout="${date}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="message" layout="${message}" />
<attribute name="host" layout="${machinename}" />
<attribute name="ActivityId" layout="${activityId}" />
<attribute name="processId" layout="${processId}" />
<attribute name="threadid" layout="${threadid}" />
<attribute name="event-properties" >
<layout type="JsonLayout" includeAllProperties="true" maxRecursionLimit="0" escapeForwardSlash="true" />
</attribute>
<attribute name="exception" layout="${exception}" />
<attribute name="traceId" layout="${var:traceId}" />
</layout>
</parameter>
<header name="X-License-Key" layout="${environment:LICENSE_KEY}"/>
</target>
</target>
</targets>
<rules>
<logger name="*" minlevel="Information" maxlevel="Error" writeTo="AsyncInformation"/>
</rules>
</nlog>
我的服务托管在 Azure 中,我可以看到代码正在运行,我还可以看到日志到达我的 API。 服务性能受到影响,CPU 使用率非常高(大部分时间为 100%),我注意到我们的打开连接已从 700 增加到 2,000(这是允许的最大连接数) 我认为这是性能问题的根源。
我试图进入 NLog 源代码并注意到 WebService 目标(我使用的)正在使用 HttpWebRequest,我认为这是打开这些大量连接的原因,因为连接不是持久性的。我想知道是否有一个选项使用 WebService 目标,但通过保持连接活动来重用连接?
或者有一个选项可以在 WebService 目标中使用 HttpClient 而不是 HttpWebRequest?
任何帮助都会很棒。
【问题讨论】: