Search code examples
multithreadingperformancenlog

Threads instantiated by NLog


We plan to use NLog on a performance critical system. Several other applications are sending log events to a LogServer application that uses NLog to write the data to several file-targets. (~10)

What threads are created by NLog in the background? (we are using async wrapped file targets only), and is there a way to influence (besides configuration) how many threads are created?

Thanks!


Solution

  • NLog doesn't create Threads, but schedules tasks/timers for the DotNet-ThreadPool:

    • NLog schedules timer-events when using AsyncWrapper for batch-writing.
    • NLog schedules tasks when doing explicit Flush/Shutdown (Flushes all configured targets in parallel)

    It usually best for the overall application-performance to use the DotNet-ThreadPool, than to create dedicated threads (unless in a special world where thread-affinity and other stuff is relevant). NLog tries to be synchronous by default, since deferring to other threads introduces performance overhead.

    See also: https://github.com/NLog/NLog/wiki/Performance