NLog - 禁用特定记录器
NLog - disable a specific logger
我想将所有记录器设置为记录到一个文件,特定 class 除外。我似乎不知道该怎么做。目前我正在尝试以下 nlog.config
无论我做什么,拦截器都在记录
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
fileName="${basedir}/logs/log.log"
maxArchiveFiles="1" archiveAboveSize="1000000" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="MyApp.DbInterceptionConfig+LoggingEFInterceptor" minlevel="Info" writeTo="file" />
</rules>
</nlog>
将 final="true"
添加到 class 将告诉它在命中该规则时停止 运行 通过其余规则。因此,您定义规则的顺序可能也很重要,以防您希望命中一条规则而不命中其他规则。
从今天开始,您可以使用 maxlevel=Off
来禁用记录器。
<logger name="Name.Space.Class3" maxlevel="Off" final="true" /> <!-- Blackhole that stops everything -->
<logger name="Name.Space.*" writeTo="target1" />
我想将所有记录器设置为记录到一个文件,特定 class 除外。我似乎不知道该怎么做。目前我正在尝试以下 nlog.config
无论我做什么,拦截器都在记录
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="File"
fileName="${basedir}/logs/log.log"
maxArchiveFiles="1" archiveAboveSize="1000000" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
<logger name="MyApp.DbInterceptionConfig+LoggingEFInterceptor" minlevel="Info" writeTo="file" />
</rules>
</nlog>
将 final="true"
添加到 class 将告诉它在命中该规则时停止 运行 通过其余规则。因此,您定义规则的顺序可能也很重要,以防您希望命中一条规则而不命中其他规则。
从今天开始,您可以使用 maxlevel=Off
来禁用记录器。
<logger name="Name.Space.Class3" maxlevel="Off" final="true" /> <!-- Blackhole that stops everything -->
<logger name="Name.Space.*" writeTo="target1" />