简体   繁体   English

如何从配置中无限期地初始化reservedFileCountLimit

[英]How to initialize retainedFileCountLimit indefinitely from config

Trying to convert the following code configuration into a config line: 尝试将以下代码配置转换为配置行:

.WriteTo.RollingFile(@"C:\Foo\Bar-{Date}.txt", retainedFileCountLimit: null)

The documentation for the rolling file sink states that in order to retain the logs indefinitely one must send the retainedFileCountLimit parameter as null . 滚动文件接收器的文档指出,为了无限期地保留日志,必须将retainedFileCountLimit参数发送为null

I tried this 我试过了

<add key="serilog:write-to:RollingFile.pathFormat" value="C:\Foo\Bar-{Date}.txt" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="null" />

but as I expected the null literal is not accepted, moreover it seems like a direct conversion to Int32 is attempted. 但是正如我所期望的那样,不接受null文字,而且似乎试图将其直接转换为Int32。

Here is the stack trace for reference: 这是堆栈跟踪以供参考:

[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +14345541
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +305
   System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +859
   System.Linq.WhereSelectEnumerableIterator`2.MoveNext() +248
   System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) +536
   System.Linq.Enumerable.ToList(IEnumerable`1 source) +80
   Serilog.Extras.AppSettings.PrefixedAppSettingsReader.ConfigureLogger(LoggerConfiguration loggerConfiguration) +1983
   Serilog.LoggerConfigurationAppSettingsExtensions.ReadAppSettings(LoggerConfiguration loggerConfiguration) +16

Serilog.FullNetFx的代码来看,我猜您根本不应该添加value属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM