Nlog: Missing log lines at heavy machine load in threaded environment

Created on 3 Sep 2018  路  6Comments  路  Source: NLog/NLog

Having an issue with missing log lines. We are creating individual logs per job passing by in a windows service. The log targets, log wrappers, logging rules and configurations are created dynamically using code.
If we run one or two jobs through the application, everything is logged fine.
If we run 4 simultaneous jobs, log lines in the middle of the log are missing. Missing chuncks of log. It is not that the log is prematurely ending. It comes back and logs again at the end. If we run it over again, there might be different log lines missing.
There aren't that many log lines per log per job. About 500 log lines.
Tried to increase the queue
Also having the log to grow.
Using NLog 4.5.9
The code:
logger

question

All 6 comments

could you please check the internal log?

Forgott to mention that i have a few errors in the internal log. However. same error even the times it logs ok as when it fails to log. I therefore bumped up the internal log level to TRACE. Unfortunately that slowed down the entire process, so it logged everything theat time. I will attach the internal log to the issue.

any idea what the cause is of the warning

error when formatting a message. Exception: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.

it's there 84 times

This line will close the old configuration, and then initialize the new configuration. During this period any loggers actively being used might not reach a working NLog-Target (as they are closing and reopening):

LogManager.Configuration = config

I suggest that you just modify the configuration directly, instead of re-assigning the configuration. This is completely threadsafe and can be done without holding any locks:

LogManager.Configuration.AddRule("*." + jobId, GetLogLevel(LogLevel), targetWrapper):
LogManager.ReconfigExistingLoggers();

Thank you very much! Worked like a charm!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sszost picture sszost  路  3Comments

ericnewton76 picture ericnewton76  路  3Comments

geedsen picture geedsen  路  3Comments

imanushin picture imanushin  路  3Comments

FaMouZx3 picture FaMouZx3  路  3Comments