serilog-settings-configuration
serilog-settings-configuration copied to clipboard
Writing to MS SQL
Hi, Can anyone shed some light on how to configure Serilog to work correctly with SQL and ASP.Net Core and Dot.Net 6, I have configured it correctly as far as I can see but it will not log to SQL, it logs okay to the console and to a log file. I have included my configuration below.
appsettings.json:
{
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.sinks.File", "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "./Logs/Log-.txt",
"rollingInterval": "Day"
}
},
{ "Name": "MSSqlServer", "Args": { "connectionString": "Server=.;Database=RevIntra;Trusted_Connection=true;MultipleActiveResultSets=true", "tableName": "DBLogs", "autoCreateSqlTable": false}}
]
}
}
Program.cs:
builder.Host.UseSerilog((ctx, lc) =>
lc.ReadFrom.Configuration(ctx.Configuration));
app.UseSerilogRequestLogging();
Regards Peter