我在我的 Windows 服务中使用 nlog 作为日志提供程序。我正在使用具有以下设置的 Visual Studio 2019 发布应用程序。
这里,nlog 配置
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
internalLogLevel="Info"
internalLogFile="c:\temp\internal-nlog.txt">
<!-- enable asp.net core layout renderers -->
<extensions>
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<!-- the targets to write to -->
<targets>
<!-- Log in a separate thread, possibly queueing up to
5000 messages. When the queue overflows, discard any
extra messages-->
<target name="file" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File" name="files" fileName="${basedir}/logs/log.current.log"
layout="${longdate}|${callsite}|${level}|${message}|${exception:format=Message,StackTrace}|${stacktrace}"
archiveFileName="${basedir}/logs/archives/log.${date:format=yyyy-MM-dd}.{#}.log "
archiveAboveSize="104857600" archiveNumbering="Rolling" maxArchiveFiles="20" concurrentWrites="true"
keepFileOpen="false" />
</target>
<target name="console" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target name="inner_console" xsi:type="ColoredConsole"
layout="${level} [${threadid}] ${logger} ${message} ${exception:format=Message,StackTrace}">
<highlight-row condition="Level==LogLevel.Fatal" foregroundColor="Red" />
<highlight-row condition="Level==LogLevel.Error" foregroundColor="Red" />
<highlight-row condition="Level==LogLevel.Warn" foregroundColor="Yellow" />
<highlight-row condition="Level==LogLevel.Info" foregroundColor="DarkCyan" />
<highlight-row condition="Level==LogLevel.Debug" foregroundColor="DarkGreen" />
</target>
</target>
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--Skip non-critical Microsoft logs and so log only own logs-->
<logger name="Microsoft.*" maxLevel="Info" final="true" />
<logger name="*" minlevel="Info" writeTo="file,console" />
</rules>
</nlog>
在生产版本构建中,它在错误日志堆栈跟踪中显示构建 PC 的代码行路径,如下所示。
in D:\SourceCode\Service\src\BulkProcessAgent.cs:line 74
有没有办法从错误日志中省略上述信息?我是否缺少 nlog 中的任何配置?