【发布时间】:2012-01-26 07:52:46
【问题描述】:
有没有办法始终将时间戳模式应用于我当前的日志文件?
这是我在 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
这没什么大不了的,因为我可以查看修改/创建的日期,但如果能快速修复它会很好。
【问题讨论】:
-
我不认为这是 100% 可能的。我确实看到了一个带有环境变量的 Kludge,它涉及每天的应用重启。如果您真的非常想要该功能,您可以创建自己的 RollingFlatFileTraceListener 版本,以这种方式工作。
-
我也没有找到解决方案,我要自己解决。
标签: c# enterprise-library enterprise-library-5