nLog:过滤或删除消息

nLog: Filter or remove message

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

记录结果

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

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" />
  ...

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

<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