【问题标题】:NLog - disable a specific loggerNLog - 禁用特定的记录器
【发布时间】:2021-08-27 13:54:29
【问题描述】:

我想将所有记录器设置为记录到一个文件中,但特定类的记录器除外。我似乎无法弄清楚该怎么做。目前我正在尝试以下 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>

【问题讨论】:

  • George,第 10 行似乎是多余的或缺少行的请求。

标签: nlog


【解决方案1】:

在类中添加final="true" 将告诉它在遇到该规则时停止运行其余规则。因此,您定义规则的顺序可能也很重要,以防您想要满足多个规则而不是其他规则。

【讨论】:

    【解决方案2】:

    从今天开始,您可以使用 maxlevel=Off 禁用记录器。

    <logger name="Name.Space.Class3" maxlevel="Off" final="true" /> <!-- Blackhole that stops everything -->
    <logger name="Name.Space.*" writeTo="target1" />
    

    Link to the documentation.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-30
      • 1970-01-01
      • 1970-01-01
      • 2011-12-21
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多