gpt4 book ai didi

c# - 如何让Serilog丰富日志

转载 作者:行者123 更新时间:2023-12-05 06:27:47 25 4
gpt4 key购买 nike

我已将 Serilog 设置为从 appsettings.json 读取其配置:

return WebHost.CreateDefaultBuilder(args)
.UseSerilog((ctx, config) => { config.ReadFrom.Configuration(ctx.Configuration); })

appsettings.json 具有以下指定增强器的相关信息:

{
"Serilog": {
"WriteTo": [
{
"Name": "RollingFile",
"Args": {
"pathFormat": "%WIDGETSAPIBASEDIR%\\logs\\log-{Date}.txt"
}
},
{
"Name": "Debug"
}
],
"Enrich": [ "CorrelationId" ]
}
}

生成的日志不包含 Enrich 属性中指定的任何数据。

我已经导入了 Serilog.Enrichers.CorrelationId,但仍然一无所获。

我也尝试过 "Enrich": [ "WithCorrelationId"]。我还尝试了其他增强器 ("FromLogContext", "WithMachineName", "WithThreadId"),但仍然一无所获。

我错过了什么?

最佳答案

这是我的有效配置文件的示例。注意到我有丰富的输出模板吗?

 "Serilog": {
"MinimumLevel": {
"Default": "Debug",
"Override": {
"Microsoft": "Warning",
"System": "Warning"
}
},
"WriteTo": [
{
"Name": "Async",
"Args": {
"configure": [
{
"Name": "File",
"Args": {
"path": ".//Logs//app.log-.txt",
"rollingInterval": "Day",
"rollOnFileSizeLimit": true,
"outputTemplate": "[{Timestamp :HH:mm:ss} {Level:u3} {SourceContext, -20} {ProcessId} {ProcessName} {ThreadId}] {Message}\n{Exception}",
,
"shared": true
}
},
{
"Name": "Console"
}
]
}
},
{
"Name": "SpectreConsole",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss} [{Level:u3} {ProcessId}] {Message:lj}{NewLine}{Exception}",
"minLevel": "Verbose"
}
}
],
"Enrich": [
"FromLogContext",
"WithMemoryUsage",
"WithProcessId",
"WithProcessName",
"WithThreadId",
"WithThreadName"
]
}

关于c# - 如何让Serilog丰富日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55010470/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com