TextWriterTraceListener trace file too large
Asked Answered
B

1

8

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?

Bikol answered 20/8, 2010 at 2:20 Comment(0)
S
5

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.
Selfsown answered 20/8, 2010 at 2:24 Comment(2)
+1 - log4net will solve this problem and has other features to offer like conditional loggingKhichabia
Sample page linked to in answer no longer exists, archived link is web.archive.org/web/20040628122447/http://weblogs.asp.net/…Gnathion

© 2022 - 2024 — McMap. All rights reserved.