Skip to content

Change NLog logging level at runtime? #35

Open
@RobertBeekman

Description

@RobertBeekman

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions