TextWriterTraceListener : can I reset/clear the output log via app.config?

2.2k views Asked by At

I have looked at the properties of the TextWriterTraceListener class and it parents and dont' see a way to add a propery to the app.config so that the log file is reset/cleared when the TraceWriter opens the file.

1

There are 1 answers

0
MatthewMartin On

Clearing the logs on appdomain start up is a surprising behavior-- most libraries are reluctant to destroy data. Creating a new file on start up or every-so-often is a more common scenario.

If the built in listeners don't meet your needs, try Essential Diagnostics (Extends Systems.Diagnostics tracing)

Ref: https://essentialdiagnostics.codeplex.com/wikipage?title=RollingFileTraceListener&referringTitle=FileLogTraceListener

Also: https://ukadcdiagnostics.codeplex.com/

And, again, assuming you are using Systems.Diagnostics for legit reasons, then you might consider extending TextWriterTraceListener & overriding the behavior you don't like and replacing it (say by adding file deletion to the constructor).

(And someone will recommend switching to log4net or nlog which have more feature to start with, so there is that)