如何在 System.Diagnostics 跟踪日志中设置翻转策略
我有一个项目,使用 System.Diagnostics 进行日志记录,
它创建了很多新的日志文件,每个文件都以 GUID 开头,
即使最后一个日志文件非常小
,我也想设置一个角色来控制新日志的创建文件
在哪里可以配置它?
第二个问题: 在哪里可以设置日志写入非UTC时间?
谢谢
I have a project, that using System.Diagnostics for logging,
And it creating lots of new logs files, each one starting with GUID,
Even when the last log file was very small
I want to setup a role that controls the creation of new log file
Where can I configure it?
And second question:
Where can I set the log to write non utc time?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有关翻转跟踪侦听器的讨论,请参阅以下链接:
什么.NET 的最佳滚动日志文件跟踪侦听器
接受的答案推荐 FileLogTraceListener:
http://msdn.microsoft.com/en-us/ Library/microsoft.visualbasic.logging.filelogtracelistener.aspx
我鼓励您也看看 Ukadc.Diagnostics 作为一种增加灵活性(和格式)的方法System.Diagnostics 跟踪/日志记录:
http://ukadcdiagnostics.codeplex.com/
回答您的最后一个问题登录 UTC 以外的其他内容,我认为唯一的答案是编写自己的 TraceListener(或使用其他人的,例如 Ukadc.Diagnostics)。
不言而喻,像 NLog 和 log4net 这样的日志框架非常受欢迎是有原因的:它们提供了极其强大且灵活的日志解决方案,使您能够专注于应用程序的功能,而不是解决日志问题。
See the following link for a discussion about rollover trace listeners:
What the best rollover log file tracelistener for .NET
The accepted answer recommends the FileLogTraceListener:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.logging.filelogtracelistener.aspx
I would encourage you to also look at Ukadc.Diagnostics as a way to add flexibility (and formatting) to System.Diagnostics tracing/logging:
http://ukadcdiagnostics.codeplex.com/
To answer your final question about logging in something other than UTC, I think the only answer is to write your own TraceListener (or use someone else's, such as Ukadc.Diagnostics).
It goes without saying that logging frameworks like NLog and log4net are very popular for a reason: they provide extremely powerful and flexible logging solutions, allowing you to focus on your application's functionality, not on solving logging problems.
我还面临着 TraceListener 标准实现的两个问题(文件大小翻转和时间戳非 UTC 事件),并且我不想使用第三方工具。
我发现这个解决方案只需最少的努力:
http://www.geekzilla.co.uk/View2C5161FE-783B-4AB7-90EF-C249CB291746.htm
I also have been faced with the both issues (filesize -rollover and Timestamps non UTC for events) of the standard implementation of TraceListener and I didn't want to have a third party tool.
I found this solution which comes with minimum effort:
http://www.geekzilla.co.uk/View2C5161FE-783B-4AB7-90EF-C249CB291746.htm