6

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?

1 Answer 1

6

There is no way provided by Serilog but this how I have solved it.

  1. Create a configuration in appsettings.json.

    {
      "EnableSerilogSelfLogs": "false",
    }
    
  2. 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.