Skip to content

FilteringWrapper target

Rolf Kristensen edited this page Nov 23, 2021 · 18 revisions

Filters log entries based on a condition.

Platforms Supported: All

Configuration Syntax

Filtering using condition:

<targets>
  <target xsi:type="FilteringWrapper" name="String" condition="Condition">
    <target xsi:type="wrappedTargetType" ...target properties... />
  </target>
</targets>

Filtering using filter (Introduced with NLog 4.6.4):

<targets>
  <target xsi:type="FilteringWrapper" name="default">
    <target xsi:type="wrappedTargetType" ...target properties... />
    <filter xsi:type="whenRepeated" layout="${message}" timeoutSeconds="30" action="Ignore" />
  </target>
</targets>

Parameters

General Options

  • name - Name of the target.

Filtering Options

  • condition - Condition Expression. Log events who meet this condition will be forwarded to the wrapped target. Condition Required, unless having specified a filter.
  • filter - Filter expression. For complex filtering logic like WhenRepeated-Filter.

    Introduced with NLog 4.6.4

Examples

Repeat filter

Filter repeated LogEvents, so it will only send mail every 5 minutes (Introduced with NLog 4.6.4):

 <nlog>
    <targets>
      <target xsi:type="FilteringWrapper" name="filter-mail">
        <target xsi:type="Mail" name="instant-mail">
          <subject>${exception:format=Type}</subject>
        </target>
        <filter type="whenRepeated" layout="${exception:format=Type}" timeoutSeconds="300" action="Ignore" />
      </target>
    </targets>
    <rules>
        <logger name='*' minlevel='Debug' writeTo='filter-mail'/>
    </rules>
</nlog>

Clone this wiki locally