I have a ASP.NET core web API where I'm using Serilog to do the logging.
I want to log Info from Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware in the log-file, but in the database I only want to log Warning from Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware.
Any easy way to this?
My current Serilog config looks more or less like this, but it logs Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware to the database.
"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File", "Serilog.Sinks.MSSqlServer" ],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.AspNetCore": "Warning",
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
}
},
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "Logs/log.txt",
"rollingInterval": "Day"
}
},
{
"Name": "MSSqlServer",
"Args": {
"connectionString": "....",
"restrictedToMinimumLevel": "Information"
// More configuration options
}
}
]
}
"restrictedToMinimumLevel": "Warning"? Are you saying you get no entries in the database or that you get too many?"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware"in the log-file and NOT in the database. Right now it is written both places.Warninginstead ofInformation. You should probably use the fluent configuration API until you get the behavior you want too, and then move those settings to JSON. C# gives you autocompletion and compiler checks. With JSON you'll only find out that something's wrong at runtime but not what's actually wrong.Warningit seems to apply to all logging to the database, not just what comes from"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware".