Ever had the problem of growing svclog files after configuring tracing in a productive WCF environment? Did not want to restart the application just for deleting or moving the trace files?
Then, you will like the
RollingXmlWriterTraceListener, which is a specialized
XmlWriterTraceListener, and is completely compatible with the WCF tracing facility.
When tracing is enabled in a WCF application, and the default
XmlWriterTraceListener is used (the listener that produces Microsoft's XML trace format, which is understood by svctraceviewer.exe), it won't allow you to delete a trace file while the application is running. And so it may happen that you see your productive server filling up its hard drive, and you are not allowed to stop it. You can spend your time in calculating when the whole system will be hanging. (Don't ask, our customer did not agree to a short downtime... even under such circumstances.)
That's why I wrote this derivate: it will start a new trace file (with a numeric, four character suffix) after a specified file size is reached.
Using the Code
Using the special trace listener is quite easy. Put the class into one of your basic libraries, adjust the namespace, and then use it instead of the default
XmlWriterTraceListener in the app.config file:
<source name="System.ServiceModel" switchValue="All">
<add name="System.ServiceModel.XmlTrace.Listener" />
<source name="System.Runtime.Serialization" switchValue="All">
<add name="System.Runtime.Serialization.XmlTrace.Listener" />
Make sure you choose the correct type and specify the assembly in which the tracer can find the type. In addition, you need to set the maximum size of a trace file before a new one is started, with the
MaxTraceFileSize attribute. This is optional, the default value is 128 MB.
- Updated the source code to conform to StyleCop and completed the XMLDoc in some places
- No functional changes applied