解决方案是将子日志记录器与serilog一起使用。然后,必须使用过滤和接收器配置子记录器。
仔细阅读与常规、配置和过滤器相关的serilog文档是关键。
{
"Serilog": {
"Using": [ "Serilog.Sinks.Literate", "Serilog.Sinks.File", "Serilog.Filters.Expressions" ],
"MinimumLevel": "Verbose",
"WriteTo": [
{
"Name": "LiterateConsole"
},
{
"Name": "File",
"Args": {
"path": "%TEMP%\\Logs\\FileWithoutFilter-.log",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}",
"rollingInterval": "Day"
}
},
{
"Name": "Logger",
"Args": {
"configureLogger": {
"Filter": [
{
"Name": "ByIncludingOnly",
"Args": {
"expression": "@Level = 'Error' and UploadError is not null"
}
}
],
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "%TEMP%\\Logs\\UPLOADERROR-.log",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
}
]
}
}
}
]
}
}
使用以前的配置,现在一切正常。