-
Notifications
You must be signed in to change notification settings - Fork 1.4k
PostFilteringWrapper target
Rolf Kristensen edited this page Jul 29, 2023
·
12 revisions
Filters buffered log entries based on a set of conditions that are evaluated on a group of events.
Platforms Supported: All
<targets>
<target xsi:type="AsyncWrapper" name="String">
<target xsi:type="PostFilteringWrapper" name="String" defaultFilter="Condition">
<target xsi:type="wrappedTargetType" ...target properties... />
<when exists="Condition" filter="Condition"/><!-- repeated -->
</target>
</target>
</targets>
- name - Name of the target.
- defaultFilter - Default filter to be applied when no specific rule matches. Conditions
-
rules - The collection of filtering rules. The rules are processed top-down and the first rule that matches determines the filtering condition to be applied to log events. Collection
Each collection item is represented by <when /> element with the following attributes:- exists - Condition to be tested. Conditions Required.
- filter - Resulting filter to be applied when the condition matches. Conditions Required.
Before NLog 4.6.4 then the filtering only worked when using PostFilteringWrapper with some type of buffering target or wrapper, such as AsyncTargetWrapper, BufferingWrapper or ASPNetBufferingWrapper. It is still a good idea add the wrapper when using the rules filtering-logic (will inspect the entire batch when a single logevent matches exists).
<targets>
<target name="file" xsi:type="BufferingWrapper" bufferSize="100">
<target xsi:type="PostFilteringWrapper" defaultFilter="level >= LogLevel.Info">
<target xsi:type="File" fileName="${basedir}/file.txt" />
<when exists="level >= LogLevel.Warn" filter="level >= LogLevel.Debug"/>
</target>
</target>
</targets>
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json