Reuben Reuben - 1 year ago 156
C# Question

NLog autoreload does not work

I created a sample windows application to test NLog. I'm just writing all the message level inside a while loop (Trace, Debug, Warn & Error). I have set

and also specified
in the NLog config file. This is working fine and printing all the messages.

I wanted to test the autoreload option and hence changed the minlevel to "Warn" manually in the config file to log only Warning messages while the application is running, but still all the messages are getting logged instead of logging only Warn and Error messages.

But if I restart the application, it takes from the config and prints only Warn and Error level messages. As far as my understanding based on the link, NLog should reload the config as and when it is changed and should start printing the logs based on the current config changes. Not sure what is wrong. Do I have to programatically reload the configuration? Please help. Following is my code,


<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns=""
xsi:schemaLocation=" NLog.xsd"
internalLogLevel="Trace" internalLogFile="c:\temp\nlog-internal.log" >


<target name="FileLogger" xsi:type="File" archiveAboveSize="1048576" fileName="Trace.log" archiveNumbering="DateAndSequence" />

<logger name="*" writeTo="FileLogger" minlevel="Debug" />

LogMessage Code Snippet

private void LogMessages(CancellationToken token)
while (true)
logger.Debug("*********** Debug *************");
logger.Trace("----------- Trace --------------");
logger.Warn("~~~~~~~~~~~ Warn ~~~~~~~~~~~~~~");
logger.Error("========== Error =============");

if (token.IsCancellationRequested)
catch (Exception ex)
throw ex;

I was suspecting whether this is happening because of thread/task and started running directly from main thread, but still the problem persists. I also tried to enable NLog internal logging to see for any errors, but couldn't find anything suspicious.

Answer Source

Have you tried setting the LogManager.GlobalThreshold property? Try doing that and don't forget to LogManager.ReconfigExistingLoggers() afterwards

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download