Skip to content

A library to allow you dynamically switch the Serilog logger log level at run time for debugging

Notifications You must be signed in to change notification settings

vantheshark/serilog-level-switcher

Repository files navigation

Serilog.LevelSwitcher Build status Travis build NuGet Version License WTFPL

A library to allow you dynamically switch the Serilog logger log level at run time for debugging purpose. For those who's using Splunk with level>=Warning, sometime we need to see lower level log events for a short period of time to debug production issue. This library is created for that reason.

Getting started

Install the Serilog.LevelSwitcher package from NuGet:

Install-Package Serilog.LevelSwitcher

To configure:

var log = new LoggerConfiguration()
    ....
    .CreateLogger()
    .OverrideLevel(new Serilog.LevelSwitcher.Options(), "redis-server:6379");

NOTE:

  • If you have multiple Logger objects, provide unique ids for each of them in the Options
  • For now, you have to manually change the key in Redis. Get key from Options class with provided logger Id (default is "Global"), the value is the expected LogEventLevel.ToString(). So if your logger Id is "MyLogger", the key will be: "Logger:MyLogger:Level" .I'm working on a separated class library to allowing CRUD those settings via web api

Not using redis?

Implement interface Serilog.LevelSwitcher.IKeyValueStore

public interface IKeyValueStore
{	
    string Get(string key);
	
    void Set(string key, string value);
}

And configure:

var log = new LoggerConfiguration()
    ....
    .CreateLogger()
    .OverrideLevel(new Serilog.LevelSwitcher.Options(), new YourKeyValueStoreImplementation());

LICENCE

License WTFPL Troll

About

A library to allow you dynamically switch the Serilog logger log level at run time for debugging

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published