Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change NLog logging level at runtime? #35

Open
RobertBeekman opened this issue May 30, 2016 · 1 comment
Open

Change NLog logging level at runtime? #35

RobertBeekman opened this issue May 30, 2016 · 1 comment

Comments

@RobertBeekman
Copy link

Hello,

I'm trying to change my logging level at runtime using the following code

var c = NLog.LogManager.Configuration;
var file = c.FindTargetByName("file") as FileTarget;
if (file == null)
    return;

var rule = c.LoggingRules.FirstOrDefault(r => r.Targets.Contains(file));
if (rule == null)
    return;

if (EnableDebug)
    rule.EnableLoggingForLevel(LogLevel.Debug);
else
    rule.DisableLoggingForLevel(LogLevel.Debug);

NLog.LogManager.ReconfigExistingLoggers();

However, this doesn't work. file and rule are both found, so it reaches the if-else statement correctly but calling NLog.LogManager.ReconfigExistingLoggers(); doesn't seem to affect existing loggers.

@michal-ciechan
Copy link

Seems to be working for me. ALthought setting it to Debug does not set it for higher levels (.g. Info/Warn) I have to set them explicitly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants