How to increase NLog log level at runtime
06:25 28 Apr 2022

My application has too much log.Trace() at the beginning of the program, causing the program to malfunction, so I can't use general NLog configuration to increase the log level.

So, I would like to increase the log level at runtime. For that, I've found something like this on the internet:

foreach (var rule in LogManager.Configuration.LoggingRules)
{
    // Iterate over all levels up to and including the target, (re)enabling them.
    for (int i = 0; i <= 5; i++)
    {
        rule.EnableLoggingForLevel(LogLevel.FromOrdinal(i));
    }
}

This, however, seems not to be working as the following line does not show up in the logs, although I'm sure this line has been passed:

log.Trace("log trace works!");

Does anybody know a way to make sure that, from a certain moment in my source code, I can see log.Trace() results?

For your information:

  1. log is defined as private static readonly Logger log = LogManager.GetCurrentClassLogger();.
  2. I've been looking for an nlog.* file, containing an tag, I didn't find anything.

Edit:
I'm working with NLog version 4.5.4.

Edit2 (try to force reading of configuration):
I've modified the nlog.config file as follows:



    
    
      
    
    ...

Then I tried to force the re-reading of that configuration, as follows:

NLog.LogManager.Setup().LoadConfigurationFromFile("C:\\...\\NLog.config");

Thanks in advance

c# debugging runtime nlog log-level