简体   繁体   English

如何在System.Diagnostics跟踪日志中设置过渡策略

[英]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.

相关问题 如何使用App.config和System.Diagnostics动态设置日志文件? - How to dynamically set log file using App.config and System.Diagnostics? 如何使用system.diagnostics将日志添加到Windows事件日志 - How to add logging to Windows Event Log using system.diagnostics 您如何使用 System.Diagnostics 以编程方式设置源开关 - How do you programatically set the source switch with System.Diagnostics 在发布System.Diagnostics之前删除日志 - Remove Log before release System.Diagnostics 如何读取所有当前进程并在控制台中打印它们? / C# ConsoleApp System.Diagnostics - How can I read all current processes and print them in console? / C# ConsoleApp System.Diagnostics 如何查看/调试System.Diagnostics计数器? - How to see/debug System.Diagnostics Counter? 如何让visual studio在每个项目中自动包含使用System.Diagnostics之类的using语句? - How can I cause visual studio to automatically include a using statement like using System.Diagnostics, in every project? 使用System.Diagnostics记录对象的聚合路径 - Log object's aggregation path using System.Diagnostics 无法使用System.Diagnostics创建新的程序实例 - Can't create new program instance using System.Diagnostics 如何使用System.Diagnostics打开(.tif)文件 - How to open (.tif) file using System.Diagnostics
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM