Reputation: 16723
What's the best practice for changing the logging level for nLog in a production environment. The only way I can change it is to modify the NLog.config file, and then recycle the app pool. Is that how it should be done?
Thanks,
Chris
Upvotes: 3
Views: 2097
Reputation: 19867
NLog 4.6.7 allows you to change NLog LogLevel dynamically with minimum effort:
<nlog>
<variable name="myLevel" value="Warn" />
<rules>
<logger minLevel="${var:myLevel}" writeTo="file" />
</rules>
</nlog>
Then you can have a Debug-button that changes the myLevel
-variable (and maybe setup a Timer that restores the default value):
LogManager.Configuration.Variables["myLevel"] = "Debug";
LogManager.ReconfigExistingLoggers(); // Explicit refresh of Layouts and updates active Logger-objects
See also: https://github.com/NLog/NLog/wiki/Filtering-log-messages#semi-dynamic-routing-rules
See also: https://github.com/NLog/NLog/wiki/Environment-specific-NLog-Logging-Configuration
Upvotes: 0
Reputation: 1898
If you want to change logging configuration, without restarting application, you should set autoReload="true".
NLog.config file:
<nlog autoReload="true">
...
</nlog>
More: https://github.com/nlog/NLog/wiki/Configuration-file#wiki-automatic-reconfiguration
Upvotes: 10