serilog-sinks-mysql
serilog-sinks-mysql copied to clipboard
Pull Configuration from appsettings.json
I am pulling Serilog into the application via WebHostBuilder as documented here: https://github.com/serilog/serilog-aspnetcore#inline-initialization
This does not appear to load the connection string or the table name from the appsettings.json file, however it is using this file to pick up the Using: Serilog.Sinks.MySQL line.
{
"Serilog": {
"Using": [ "Serilog.Sinks.MySQL" ],
"LevelSwitches": { "$controlSwitch": "Verbose" },
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning"
}
},
"WriteTo": [
{
"Name": "Debug"
},
{
"Name": "MySQL",
"Args": {
"connectionString": "Serilog",
"tableName": "serilog",
"storeTimestampInUtc": "false"
}
}
],
"Enrich": [ "FromLogContext" ]
},
"ConnectionStrings": {
"Serilog": "Server=<my server>;Database=<my db>;Uid=<my user>;Pwd=<mypassword>;"
}
}
If I specify the connection string manually by adding the following line to the code documented in the link above, everything works normally:
.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
.ReadFrom.Configuration(hostingContext.Configuration)
.WriteTo.MySQL(hostingContext.Configuration.GetConnectionString("Serilog")))
Do I have the configuration incorrect in the settings file?
Does work for you? Thanks