TextWriterTraceListener 跟踪文件太大
我正在使用 C# System.Diagnostics.TextWriterTraceListener
来打印跟踪。但跟踪文件变得太大(数百 MB)。 我想更改 TextWriterTraceListener
的行为,如果跟踪文件变大,它将输出写入另一个文件。 例如,原始跟踪文件是“output1.txt”,如果它变得大于100MB,则TextWriterTraceListener应该写入“output2.txt”。
您遇到过类似的问题吗?有什么优雅的解决方案吗?
I am using C# System.Diagnostics.TextWriterTraceListener
to print trace. But the trace file becomes too large (hundreds of MBs).
I want to change the behavior of TextWriterTraceListener
, that if the trace file becomes large, it writes output to another file.
For example, the original trace file is 'output1.txt', if it becomes larger than 100MB, then TextWriterTraceListener should write to 'output2.txt'.
Have you encountereds similar problems? Are there any elegant solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能想到的两个选项:
TextWriter
实现来执行此操作,并将TextWriterTraceListener.Writer
属性设置为其实例。这是一个执行此操作的 示例 实现,尽管它按时间(每天)滚动,而不是按文件大小滚动。RollingFileAppender
。Two options I can think of:
TextWriter
implementation that does this, and set theTextWriterTraceListener.Writer
property to an instance of it. Here's a sample implementation that does this, although it rolls over on a time (daily) basis rather than on a file-size basis.RollingFileAppender
.