-
Notifications
You must be signed in to change notification settings - Fork 1.4k
FilteringWrapper target
Rolf Kristensen edited this page Nov 23, 2021
·
18 revisions
Filters log entries based on a condition.
Platforms Supported: All
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>- name - Name of the target.
- 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
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>- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json