TextWriterTraceListener 跟踪文件太大

发布于 2024-09-14 19:48:14 字数 277 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若无相欠,怎会相见 2024-09-21 19:48:14

我能想到的两个选项:

  1. 编写自己的 TextWriter 实现来执行此操作,并将 TextWriterTraceListener.Writer 属性设置为其实例。这是一个执行此操作的 示例 实现,尽管它按时间(每天)滚动,而不是按文件大小滚动。
  2. 切换到 log4net 并使用 RollingFileAppender

Two options I can think of:

  1. Write your own TextWriter implementation that does this, and set the TextWriterTraceListener.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.
  2. Switch to log4net and use a RollingFileAppender.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文