我有以下nlog配置。我只想不记录来自Meazure.Core.SiteContext
的任何非错误消息。
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<extensions>
<add assembly="NLog.Targets.GrowlNotify" />
<add assembly="Gelf4NLog.Target" />
</extensions>
<targets>
<target name="file" xsi:type="File" fileName="${basedir}/log.log" layout="${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=Type,Message,StackTrace:innerFormat=Type,Message,StackTrace:maxInnerExceptionLevel=10:innerExceptionSeparator=\n\t}" maxArchiveFiles="1" archiveAboveSize="1000000" />
<target name="dev" xsi:type="Console" />
<target name="growl" type="GrowlNotify" host="" password="" />
</targets>
<rules>
<logger name="Meazure.Core.SiteContext" minlevel="Error" writeTo="file" final="true" />
<logger name="*" minlevel="Trace" writeTo="dev" />
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minLevel="Info" writeTo="growl" />
</rules>
</nlog>
它不起作用!我仍然在file
2016-03-23 15:08:58.0125|DEBUG|Meazure.Core.SiteContext|Closed connection at 2016-03-23 3:08:58 PM -07:00
我做错了什么?
答案 0 :(得分:1)
最终规则适用于组合:
使用loggername&#34; Meazure.Core.SiteContext&#34;和minlevel&#34;错误&#34;不会去记录规则2-4。但是如果等级是&#34; debug&#34;它会。
实现此目的的最佳方法是使用Null target:
新目标:
<target name="null" xsi:type="Null" />
规则:
<logger name="Meazure.Core.SiteContext" minlevel="Error" writeTo="file" final="true" />
<logger name="Meazure.Core.SiteContext" writeTo="null" final="true"/>
<logger name="*" minlevel="Trace" writeTo="dev" />
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="*" minLevel="Info" writeTo="growl" />