如何在Serilog中记录消息模板的字段名称



在使用输出模板时,Serilog中是否有告诉记录消息模板中变量的名称的设置?

_logger.LogWarning(@"Role with Id {RoleId} not found", id);

我使用日志记录到文件,并希望看到RoleId字段与消息一起记录在文件中,这样我就可以使用此字段进行筛选。我的序列号设置看起来像

"Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft.EntityFrameworkCore.Storage.IRelationalCommandBuilderFactory": "Warning"
}
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "bin/Debug/netcoreapp2.0/Logs/log-.txt",
"rollingInterval": "Day",
"outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} {Level:u3} {SourceContext} {Message:lj} {RequestId} {Properties} {NewLine} {Exception}"
//"formatter": "Serilog.Formatting.Compact.CompactJsonFormatter, Serilog.Formatting.Compact"
}
}] 

}

我知道我可以使用LogContext.PushProperty("RoleId", id),但在我的情况下,这不是使用CompactJsonFormatter的选项。

我发现日志是否写入文件,并且$后面跟着字段(NOT对象((_logger.LogWarning("Role with Id {$RoleId} not found", id);)序列号将生成消息模板、带$符号的字段名称和字段值。CCD_ 5也需要在CCD_ 6中指定。

最新更新