-
Notifications
You must be signed in to change notification settings - Fork 1.4k
AutoFlushWrapper target
Causes a flush on a wrapped target if LogEvent satisfies provided condition.
If condition isn't set, a flush will occur after each successful write.
Platforms Supported: All
<targets>
<target xsi:type="AutoFlushWrapper" name="String" condition="Condition">
<target xsi:type="wrappedTargetType" ...target properties... />
</target>
</targets>
-
name - Name of the target.
-
condition - Condition is expression used to determine if flush must be executed.
Introduced in NLog 4.4
-
asyncFlush - Delay the flush until the LogEvent has been confirmed as written. Default
true
.Introduced in NLog 4.4.6 where BufferingWrapper-target defaults to
false
, to avoid waiting long time (forever) to flushNLog 4.7 implements same behavior for AsyncTaskTarget so it defaults to
false
, to reduce waiting time for flush. -
flushOnConditionOnly - Ignores explicit flush operations caused by calling
NLog.LogManager.Flush()
orNLog.LogManager.Shutdown()
. Useful when combined with BufferingWrapper andoverflowAction=Discard
.Introduced in NLog 4.6.6
Flush into target on each write
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="AutoFlushWrapper">
<target xsi:type="File" fileName="${basedir}/file.txt" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</rules>
</nlog>
Flush into target, if LogEvent level >= Warn (introduced in NLog 4.4)
<?xml version="1.0" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="file" xsi:type="AutoFlushWrapper" condition="level >= LogLevel.Warn">
<target xsi:type="bufferingWrapper" overflowAction="Discard">
<target xsi:type="File" fileName="${basedir}/file.txt" />
</target>
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="file" />
</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