I just discovered Serilog and I love it. However, I'm struggling to get it to read 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;
The commented out sections are the configuration values I want to read from a config file.
The config 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'm using 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 app. I'm not seeing any errors on the console.
Serilog.Debugging.SelfLog.Out = Console.Out;
What am I missing?
It looks like you may have a typo in the configuration:
serilog:writeto:MSSqlServer.tableName
Missing the dash:
serilog:write-to:MSSqlServer.tableName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With