NLog performance

You only need to add the async attribute to your targets element:

<targets async="true">
        <target name="file" xsi:type="File" fileName="${basedir}/log.txt" />

instead of

<targets>
    <target name="asyncFile" xsi:type="AsyncWrapper">
        <target name="file" xsi:type="File" fileName="${basedir}/log.txt" />
    </target>

I guess I didn’t get that far into the documentation 😉

Asynchronous target wrapper allows the
logger code to execute more quickly,
by queueing messages and processing
them in a separate thread. You should
wrap targets that spend a non-trivial
amount of time in their Write() method
with asynchronous target to speed up
logging. Because asynchronous logging
is quite a common scenario, NLog
supports a shorthand notation for
wrapping all targets with
AsyncWrapper. Just add async=”true” to
the element in the
configuration file. … your targets go here

Keep in mind that using async logging can cause certain messages to be discarded. This is by design.


ref: https://github.com/nlog/NLog/wiki/AsyncWrapper-target#async-attribute-and-asyncwrapper

Async attribute and AsyncWrapper

Don’t combine the Async attribute and AsyncWrapper. This will only slow down processing and will behave unreliably.

Async attribute will discard by default

The async attribute is a shorthand for:


xsi:type="AsyncWrapper overflowAction="Discard" queueLimit="10000" batchSize="100" timeToSleepBetweenBatches="50"

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)