【问题标题】:nLog: Filter or remove messagenLog:过滤或删除消息
【发布时间】:2018-06-26 04:01:50
【问题描述】:

如何从信息级别日志中过滤或删除不需要的消息? 这是我的日志结果。

日志结果

我只想记录黄色。但是无论我尝试什么,我都无法在上面的黄色之前和之后删除额外的日志。这是我的代码。

public IActionResult Index()
{
    _logger.LogInformation("--- THIS IS MY MESSAGE ---");
    return View();
}

nlog.config

  ...
<target xsi:type="File" name="activityLog" fileName="${gdc:item=appbasepath}\Logs\log-activity-${shortdate}.log"
        layout="${longdate}|${uppercase:${level}}|${message:raw=true}" />
  ...
<logger name="*" level="Info" writeTo="activityLog" />
  ...

【问题讨论】:

标签: asp.net-core nlog


【解决方案1】:

添加规则以丢弃多余的消息

<rules>
   <!--All logs, including from Microsoft-->
   <logger name="*" minlevel="Trace" writeTo="allfile" />

   <!--Skip non-critical Microsoft logs and so log only own logs-->
   <logger name="Microsoft.*" maxLevel="Info" final="true" /> <!-- BlackHole without writeTo -->
   <logger name="*" minlevel="Trace" writeTo="ownFile-web" />
</rules>

NLog Wiki - Getting Started

【讨论】:

  • 我的错误。我输入了代码,但顺序错误。谢谢。 :-)
猜你喜欢
  • 2018-11-21
  • 1970-01-01
  • 1970-01-01
  • 2018-06-29
  • 2016-08-30
  • 2020-03-31
  • 2014-07-22
  • 1970-01-01
  • 2023-03-04
相关资源
最近更新 更多