企业库日志记录 5 - 滚动平面文件
有没有办法始终将时间戳模式应用于我当前的日志文件?
这是来自 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
这并不是什么大不了的事情,因为我可以只查看修改/创建的日期,但如果它是一个快速修复,那就太好了。
Is there a way to always have the timestamppattern applied to my current log files?
Here is an example of my log file listener from 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" />
Now once I hit the max size or date change, it renames the logs, but is there a way I can get the initial log file to show up with the TimeStamp Pattern?
I get this in my logs folder:
exception.log <-- Current log
exception.2011-12-22.1.log
exception.2011.12.22.2.log
I'd like this:
exception.2011-12-22.log (or exception.2011-12-22.1.log) <-- Current Log
exception.2011.12.22.2.log
Its not a huge deal as I can just look at the date modified/created, but it would be nice if its a quick fix.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
像这样将文件名作为时间戳给出怎么样:Exception.2011-12-22.log
您可以通过 Fluent api 来完成此操作,或者如果您不想从代码中使用它,您可以每天更改配置文件。如果配置文件更改,日志块可以自动更改配置。但这当然会让你的代码有点复杂。
只是一个想法...
What about giving the name of file as timestamp like this: exception.2011-12-22.log
You can do this by fluent api or if you dont want to use it from code you can change the config file everyday.If config file changes, Logging block automatically can change configuration. But of course this gonna make your code little bit complex.
Just an idea...