开发者

How can I set the rollover strategy in System.Diagnostics trace log

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


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. 


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜