itmannz
itmannz

Reputation: 599

serilog LoggerConfiguration via webconfig

How can I make LoggerConfiguration is manage via Web.config (appsetting) such as Verbose/Debug etc.

Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Verbose()// I want to make is configurable via web.config.
    .Enrich.FromLogContext()                    
    .WriteTo.Seq(serilogUrl)
    .CreateLogger();

Upvotes: 1

Views: 2629

Answers (2)

Vočko
Vočko

Reputation: 2996

You have to use the library that @C. Augusto Proiete linked (Serilog.Settings.AppSettings).

There is a good documentation with examples on this this page.

Upvotes: 0

C. Augusto Proiete
C. Augusto Proiete

Reputation: 27908

Use Serilog.Settings.AppSettings

Log.Logger = new LoggerConfiguration()
  .ReadFrom.AppSettings()
  ... // Other configuration here, then
  .CreateLogger();

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="serilog:minimum-level" value="Verbose" />
    <!-- More settings here -->
  </appSettings>
</configuration>

Serilog's documentation is quite good. You should check it out: https://serilog.net

enter image description here

Upvotes: 3

Related Questions