I was looking over some of the best practices for NLog when I noticed following target configuration:
<targets async="true">
<default-wrapper xsi:type="BufferingWrapper" bufferSize="100"/>
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${uppercase:${level}} ${message}" />
<!-- other stuff -->
</targets>
From what I understand this wraps the file target with AsyncWrapper as well as with BufferingWrapper...
What is the difference between the two? Do I need both, since NLog site describes both as "buffering"....
Once there are enough messages (specified by bufferSize parameter) in the buffer, BufferingWrapper will block and write the messages to its target. The caller will need to wait until the writing is finished.
AsynWrapper uses a separate thread to handle the writes. The calls return immediately and the caller can continue its work and the log gets written later.
BufferingWrapper works as a throttle, so it queues up messages before writing them to the actual target. For example, writing an email with all alerts every 1 minute.
AsyncWrapper uses a background thread for writing to the actual target, so the application-code logging will not be blocked. The AsyncWrapper
improves concurrency when having many application-threads logging to the same target. The AsyncWrapper
also improves target-throughput by writing in small batches, instead of one LogEvent
at a time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With