How to use ReadFrom.AppSettings in Serilog

I just opened Serylogue and I like it. However, I'm struggling to read it from app.config.

Code Configuration:

ILogger logger = new LoggerConfiguration()
    .ReadFrom.AppSettings()
    //.MinimumLevel.Verbose()
    .Enrich.WithProcessId()
    .Enrich.WithThreadId()
    .Enrich.WithMachineName()
    .Destructure.UsingAttributes()
    //.WriteTo.MSSqlServer(@"Server=EVDVWADBV1;Database=AppLog;Trusted_Connection=True;", "Logs")
    .CreateLogger();
Log.Logger = logger;

Commented sections are the configuration values ​​that I want to read from the configuration file.

The configuration file contains:

<appSettings>
    <add key="serilog:minimum-level" value="Verbose"/>
    <add key="serilog:using" value="Serilog.Sinks.MSSqlServer"/>
    <add key="serilog:write-to:MSSqlServer.connectionString" value="Server=EVDVWADBV1;Database=AppLog;Trusted_Connection=True;"/>
    <add key="serilog:writeto:MSSqlServer.tableName" value="Logs"/>
    <add key="serilog:write-to:RollingFile.pathFormat" value="C:\Logs\myapp-{Date}.txt" />
    <add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="10" />
</appSettings>

I use the following Serilog packages.

<package id="Serilog" version="1.5.14" targetFramework="net452" />
<package id="Serilog.Sinks.MSSqlServer" version="3.0.41" targetFramework="net452" />

I also added this as the first line of my console application. I do not see any errors on the console.

Serilog.Debugging.SelfLog.Out = Console.Out;

What am I missing?

+4
source share
1 answer

It looks like you might have a typo in the configuration:

serilog:writeto:MSSqlServer.tableName

Missing dash:

serilog:write-to:MSSqlServer.tableName
+1
source

Source: https://habr.com/ru/post/1627510/


All Articles