有没有办法始终将时间戳模式应用于我当前的日志文件?
这是来自 app.config 的我的日志文件监听器的示例
<add name="Exception" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
fileName="%APPDATA%\MyProgram\Logs\exception.log" formatter="PrismText"
rollFileExistsBehavior="Increment" rollInterval="Day" timeStampPattern="yyyy-MM-dd" rollSizeKB="3000"
maxArchivedFiles="10" />
现在一旦我达到最大大小或日期更改,它就会重命名日志,但是有没有办法让初始日志文件与时间戳模式一起显示?
我在我的日志文件夹中得到这个:
exception.log <-- Current log
exception.2011-12-22.1.log
exception.2011.12.22.2.log
我想要这样:
exception.2011-12-22.log (or exception.2011-12-22.1.log) <-- Current Log
exception.2011.12.22.2.log
这没什么大不了的,因为我可以只查看修改/创建的日期,但如果它能快速修复就更好了。
最佳答案
像这样将文件名作为时间戳怎么样:exception.2011-12-22.log
您可以通过流畅的 api 来执行此操作,或者如果您不想从代码中使用它,您可以每天更改配置文件。如果配置文件发生更改,日志记录 block 会自动更改配置。但是,这当然会使您的代码有点复杂。
只是一个想法...
关于c# - Enterprise Library Logging 5 - 滚动平面文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8607835/