Skip to content

Latest commit

 

History

History
39 lines (29 loc) · 1.72 KB

Filtering-log-messages.md

File metadata and controls

39 lines (29 loc) · 1.72 KB

Log messages may be filtered via either routing or filtering.

Filters

With the use of <filters> you may ignore (blacklist) and/or allow (whitelist) events. See the <when> filter.

e.g.

<logger name="*" writeTo="file">
   <filters>
    <when condition="length('${message}') > 100" action="Ignore" />
  </filters>
</logger> 

Routing

Logging Rules is the most efficient way to perform filtering using the name of the Logger.

By not specifying writeTo= then it act like a blackhole with almost no overhead:

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

<rules>
   <!-- ignore events written that are written to a logger which starts with "Namespace." -->
   <logger name="Namespace.*" minlevel="Trace" final="true" /> <!-- BlackHole that swallows everything -->
   <logger name="Namespace.*" maxLevel="Info" final="true" />  <!-- BlackHole that swallows non-critical -->
</rules>

Compared to the <filters> this is more efficient and could be easier to write.

Deprecated filters

These filters are deprecated. They have been replace by the <when> filter, which exposes uses modifiable conditions for filtering log events.