I trying to configure Serilog to separate normal logs and entity framework logging. Here is my serilog configuration:
"Serilog": {
"Using": [
"Serilog.Settings.Configuration",
"Serilog.Sinks.File"
],
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Debug",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "RollingFile",
"Args": {
"configureLogger": {
"WriteTo": [
{
"Name": "LogFile",
"Args": {
"textFormatter": "JsonFormatter",
"fileSizeLimitBytes": 2147483648,
"retainedFileCountLimit": 5
}
}
]
},
"pathFormat": "log-{Date}.log",
"logDirectory": ".",
"Filter": [
{
"Name": "ByExcluding",
"Args": {
"expression": "StartsWith(SourceContext, 'Microsoft.EntityFrameworkCore.')"
}
}
]
}
},
{
"Name": "RollingFile2",
"Args": {
"configureLogger": {
"WriteTo": [
{
"Name": "LogFile2",
"Args": {
"textFormatter": "JsonFormatter",
"fileSizeLimitBytes": 2147483648,
"retainedFileCountLimit": 5
}
}
]
},
"pathFormat": "log-DB-{Date}.log",
"logDirectory": ".",
"Filter": [
{
"Name": "ByIncluding",
"Args": {
"expression": "StartsWith(SourceContext, 'Microsoft.EntityFrameworkCore.')"
}
}
]
}
},
{
"Name": "Console",
"Args": {
"outputTemplate": "{Timestamp:HH:mm:ss} [{Level}] ({CorrelationToken}) {Message}{NewLine}{Exception}"
}
}
],
"Enrich": [
"FromLogContext",
"WithMachineName",
"WithProcessId",
"WithThreadId",
"WithHttpRequestId"
]
}
I do not get a second log file. I base myself on this post to realize my configuration Filter Serilog logs to different sinks depending on context source?
What did I not understand in the serilog configuration? I find a lot of configuration examples via the code but very little via the appsettings.json. I prefer to use appsetting.json
Thanks.