Click here to Skip to main content
14,141,310 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 13 Nov 2008
Licenced LGPL3

A Rolling XmlWriterTraceListener

, 15 Nov 2008
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

You may also be interested in...

Comments and Discussions

GeneralRe: client crashed when using RollingXmlWriterTraceListener Pin
Member 465801613-Sep-10 6:46
memberMember 465801613-Sep-10 6:46 
GeneralRe: client crashed when using RollingXmlWriterTraceListener Pin
midix18-Mar-13 1:33
membermidix18-Mar-13 1:33 
GeneralClosing and Disposing streams Pin
Gaston Verelst5-Jan-10 2:45
memberGaston Verelst5-Jan-10 2:45 
GeneralRe: Closing and Disposing streams Pin
Member 311913114-Jun-11 11:49
memberMember 311913114-Jun-11 11:49 
GeneralRe: Closing and Disposing streams Pin
Geekian_senate20-Oct-11 5:31
memberGeekian_senate20-Oct-11 5:31 
GeneralRe: Closing and Disposing streams Pin
Rakesh690610-Feb-14 0:46
memberRakesh690610-Feb-14 0:46 
QuestionTest app? Pin
ccfoo24215-Jan-09 4:53
memberccfoo24215-Jan-09 4:53 

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

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

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web05 | 2.8.190518.1 | Last Updated 15 Nov 2008
Article Copyright 2008 by marc_opus
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid