The docs only show how to enable Selflog programmatically. I would like to enable/disable it by just updating the config file.
Is there a way to enable selflog from config file the same we do to define loggers and sinks?
There is no way provided by Serilog but this how I have solved it.
Create a configuration in appsettings.json.
{
"EnableSerilogSelfLogs": "false",
}
Read configuration in program.cs and call the required method.
if(enableSelfLogs)
{
var fileName = File.AppendText(Path.Combine(logDir, "_SerilogSelfLogs.txt"));
Serilog.Debugging.SelfLog.Enable(TextWriter.Synchronized(fileName));
}
hope it helps.