serilog.settings.appsettings 和文件滚动更新间隔的问题



我正在使用SeriLog登录基于IdentityServer3的身份验证服务。我刚刚将 serilog.sinks.literate 插件替换为 serilog.sinks.file 插件,以便获得 File 插件提供的滚动文件功能。当我在 Startup.cs 中使用具有以下配置代码的文件插件时,它按我预期工作。(我只使用 RolloverInterval.Minute 进行测试。当我部署代码时,我将切换到 RolloverInterval.Day。

Log.Logger = new LoggerConfiguration()
.WriteTo.File("E:\Site\AuthSvc\Trace.log", rollingInterval: RollingInterval.Minute, retainedFileCountLimit: 10)
.CreateLogger();

正如我所说,这按预期工作,每分钟创建一个新文件。

现在我尝试使用 serilog.settings.appsettings 插件在 appSettings 而不是代码中管理所有这些配置。所以我将上面的代码更改为:

Log.Logger = new LoggerConfiguration()
.ReadFrom.AppSettings()
.CreateLogger();

我在我的 web.config 应用程序设置中包含以下内容:

<add key="serilog:minimum-level" value="Debug"/>
<add key="serilog:using:File" value="Serilog.Sinks.File"/>
<add key="serilog:write-to:File.path" value="E:SiteAuthSvcTrace.log"/>
<add key="serilog:write-to:File.rollingInterval" value="RollingInterval.Minute"/>
<add key="serilog:write-to:File.retainedFileCountLimit" value="10"/>

当我使用上述配置运行服务时,我收到错误消息"找不到请求的值'滚动间隔.分钟'"。任何滚动间隔值都会发生类似的错误。

如果我删除最后两个应用程序设置,它工作正常。是我做错了什么,还是应用设置插件不支持文件接收器插件的滚动文件功能?

我不确定这是否被记录下来(我会检查(,但是当通过Serilog.Settings.AppSettings设置枚举的值时,您只指定枚举成员名称,而不指定枚举的名称。

例如,代替

<add key="serilog:write-to:File.rollingInterval" value="RollingInterval.Minute"/>

<add key="serilog:write-to:File.rollingInterval" value="Minute"/>

这在appsettings.json文件中对我有用:

"Serilog": {
"Using": [ "Serilog.Sinks.Console", "Serilog.Sinks.File" ],
"MinimumLevel": "Debug",
"WriteTo": [
{ "Name": "Console" },
{
"Name": "File",
"Args": {
"path": "C:\Temp\log-.log",
"rollingInterval": "Day"
}
}
],
"Properties": {
"Application": "MyService"
}
}

最新更新