[英]How can I set the rollover strategy in System.Diagnostics trace log
I have a project, that using System.Diagnostics for logging, 我有一个项目,使用System.Diagnostics进行记录,
And it creating lots of new logs files, each one starting with GUID, 并且它创建了许多新的日志文件,每个文件都以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? 第二个问题:我在哪里可以将日志设置为非UTC时间?
Thanks 谢谢
See the following link for a discussion about rollover trace listeners: 请参阅以下链接,以获取有关过渡跟踪侦听器的讨论:
What the best rollover log file tracelistener for .NET 什么是.NET最好的过渡日志文件tracelistener
The accepted answer recommends the FileLogTraceListener: 接受的答案推荐FileLogTraceListener:
http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.logging.filelogtracelistener.aspx http://msdn.microsoft.com/zh-cn/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: 我鼓励您也将Ukadc.Diagnostics视为一种增加System.Diagnostics跟踪/记录灵活性(和格式)的方法:
http://ukadcdiagnostics.codeplex.com/ 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). 要回答有关登录UTC以外的其他问题,我认为唯一的答案是编写自己的TraceListener(或使用其他人的监听器,例如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. 不言而喻,诸如NLog和log4net之类的日志记录框架非常流行是有原因的:它们提供了非常强大和灵活的日志记录解决方案,使您可以专注于应用程序的功能,而不是解决日志记录问题。
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. 我还遇到了TraceListener的标准实现的两个问题(文件大小-rollover和Timestamps非UTC用于事件),并且我不想拥有第三方工具。
I found this solution which comes with minimum effort: 我发现了这种解决方案,它花费了最少的精力:
http://www.geekzilla.co.uk/View2C5161FE-783B-4AB7-90EF-C249CB291746.htm http://www.geekzilla.co.uk/View2C5161FE-783B-4AB7-90EF-C249CB291746.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.