首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NLog规则排序

NLog规则排序
EN

Stack Overflow用户
提问于 2015-08-06 15:34:15
回答 1查看 1.1K关注 0票数 1

我已经看到了一些从特定名称空间中抑制日志的例子,但它们似乎都抑制了除了名称空间之外的所有东西,而不是相反的(也就是说,“为这个名称空间提供增强的日志记录,并禁止其他所有的日志记录”等等)。

请有人解释一下为什么下面的配置不禁止My.Namespace命名空间中的记录器?目标是确保My.Namespace命名空间中的任何记录器只记录错误,而其他所有内容都不受影响。

代码语言:javascript
复制
<configSections>
  <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>

<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <targets async="true">
    <target name="console" xsi:type="Console" layout="${level} ${message}" />
  </targets>

  <rules>
    <logger name="My.Namespace.*" minlevel="Error" writeTo="console" final="true" />
    <logger name="*" minlevel="Debug" writeTo="console" />
  </rules>
</nlog>
EN

回答 1

Stack Overflow用户

发布于 2015-08-07 09:57:21

虽然我认为更清楚的是能够为名称空间抑制设置一个总括规则,但我已经成功地实现了以下配置:

代码语言:javascript
复制
<targets async="true">
  <target xsi:type="Console" name="console" layout="${longdate} ${level} ${message}" />
</targets>

<rules>
  <!-- Anything less or equal to DEBUG, don't write to anything (no target) -->
  <logger name="My.Namespace.*" maxlevel="Debug" final="true" />

  <!-- Anything greater or equal to INFO, write to the console target -->
  <logger name="My.Namespace.*" minlevel="Info" writeTo="console" final="true" />
  <logger name="*" minlevel="Debug" writeTo="console" />
</rules>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31859974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档