Search code examples
c#nlog

How to prevent nlog from using config file?


NLog's behavior can be configured both via configuration files and programmatically.

It seems like when I set up programmatic rules, any configuration file present is still processed, so both mechanisms are in play at the same time. Is this accurate?

Is it possible to set up NLog to use only programmatic rules and prevent it from reading any config files?


Solution

  • LogManager.Configuration = new LoggingConfiguration(); // Assigns configuration from code
    Logger Log = LogManager.GetCurrentClassLogger(); // Only loads configuration from xml file, when no configuration assigned
    

    if you use one of these methods, respectively, and it will work

    more info: https://github.com/nlog/nlog/wiki