Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nlog .netcore turn off microsoft INFO level logging

How can I turn off Microsoft info level logging in nlog / .netcore ?

I still want info logging for my other loggers

I currently have:

  <rules>
    <logger name="Microsoft.*" minlevel="Error" writeTo="nxlog_json" />
    <logger name="Microsoft.*" minlevel="Error" writeTo="human_text_file" />
    <logger name="*" minlevel="Info" writeTo="nxlog_json" />
    <logger name="*" minlevel="Info" writeTo="human_text_file" />
  </rules>

This does not work, If i remove:

<logger name="*" minlevel="Info" writeTo="nxlog_json" />
<logger name="*" minlevel="Info" writeTo="human_text_file" />

It does work for the microsoft logging , but then removes all logging for the other loggers.

What am i missing ? I am assuming the logger name="" overrides the first entrys for Microsoft., but I don't want to have to explicitly specify my other loggers names.

like image 694
user3451887 Avatar asked May 21 '18 10:05

user3451887


1 Answers

Use final=true that stops other filters processing if current filter applyed. And write "blackHole" target to swallow messages:

<targets>
  <target xsi:type="Null" name="blackHole" />
</targets>
<rules>
  <logger name="Microsoft.*" minlevel="Info" writeTo="blackHole" final="true" />
  <logger name="*" minlevel="Info" writeTo="nxlog_json" />
  <logger name="*" minlevel="Info" writeTo="human_text_file" />
</rules>

NLog 4.5 allows one to specify an empty writeTo=""

<rules>
  <logger name="Microsoft.*" minlevel="Info" writeTo="" final="true" />
  <logger name="*" minlevel="Info" writeTo="nxlog_json" />
  <logger name="*" minlevel="Info" writeTo="human_text_file" />
</rules>

Official wiki: https://github.com/NLog/NLog/wiki/Filtering-log-messages#routing

like image 115
Alexey.Petriashev Avatar answered Sep 18 '22 17:09

Alexey.Petriashev