Click here to Skip to main content
Click here to Skip to main content

A Rolling XmlWriterTraceListener

, 15 Nov 2008 LGPL3
Rate this:
Please Sign up or sign in to vote.
A derivation of XmlWriterTraceListener that manages the size of your trace files automatically


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:

<?xml version="1.0"?>

            <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" />

                type="MarcW.Tools.Diagnostics.RollingXmlWriterTraceListener, MarcW.Tools"
                MaxTraceFileSize="134217728" />
                type="MarcW.Tools.Diagnostics.RollingXmlWriterTraceListener, MarcW.Tools"
                MaxTraceFileSize="134217728" />


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.


  • 2008-11-13
    • First issue
  • 2008-11-14
    • Updated the source code to conform to StyleCop and completed the XMLDoc in some places
    • No functional changes applied


This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


About the Author

Software Developer OPUS GmbH
Germany Germany
C# Developer for KLUSA

Comments and Discussions

QuestionAdded System.ServiceModel.MessageLogging PinmemberMember 1107155717-Nov-14 0:30 
AnswerRe: Added System.ServiceModel.MessageLogging PinmemberMember 1107155717-Nov-14 2:10 
QuestionUpdated Version? Pinmemberrleonard5525-Sep-14 4:18 
AnswerRe: Updated Version? PinmemberMember 1107155713-Nov-14 2:17 
QuestionFlush doesn't flush data imediatly to file PinmemberToolMaker200719-Sep-13 5:17 
QuestionFails if directory does not exist PinmemberDarkWalkerRzn29-Apr-13 23:47 
QuestionProduction environment PinmemberMember 99630573-Apr-13 8:55 
AnswerRe: Production environment PinmemberJohnson.Net15-Nov-13 2:19 
QuestionAttributes are empty Pinmemberpkoeppe13-Nov-12 20:52 
BugRe: Attributes are empty PinmemberMember 854221628-Jan-13 1:44 
GeneralRe: Attributes are empty PinmemberJohnson.Net15-Nov-13 2:11 
QuestionLog is getting cleared everytime the service gets cycled. PinmemberArchie collins10-Jul-12 10:02 
SuggestionFix for improper termination of XML tags in trace files PinmemberUllas Chacko8-Jul-12 16:19 
QuestionNot working :( PinmemberKenny Woo3-Jul-12 21:56 
AnswerRe: Not working :( Pinmembermarc_opus3-Jul-12 22:06 
GeneralRe: Not working :( PinmemberKenny Woo6-Jul-12 1:05 
GeneralRe: Not working :( Pinmemberoren.shnitzer9-Oct-12 22:59 
GeneralMy vote of 5 Pinmemberrajeevtechnical3-Oct-11 5:17 
QuestionWhy the second constructor does not set the current prefix? PinmemberPhilGood19-Jul-11 5:37 
AnswerRe: Why the second constructor does not set the current prefix? Pinmemberpkkalra197830-Jan-12 16:08 
Generalclient crashed when using RollingXmlWriterTraceListener PinmemberMember 465801610-Sep-10 15:21 
GeneralRe: client crashed when using RollingXmlWriterTraceListener Pinmembermarc_opus10-Sep-10 21:19 
GeneralRe: client crashed when using RollingXmlWriterTraceListener PinmemberMember 465801613-Sep-10 7:46 
GeneralRe: client crashed when using RollingXmlWriterTraceListener Pinmembermidix18-Mar-13 2:33 
GeneralClosing and Disposing streams PinmemberGastonV5-Jan-10 3:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.141223.1 | Last Updated 15 Nov 2008
Article Copyright 2008 by marc_opus
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid