Rolling File Trace Listener Extension for Enterprise Library 2.0

[Update 2006-04-18: Removed obsolete information from this blog entry. The latest information about the RollingFileTraceListener and the download link can always be found in this article on my blog.]

In January 2006 Microsoft released version 2.0 of the Enterprise Library. The Logging block now uses the trace listeners infrastructure of the .NET Framework 2.0 instead of "logging sinks". Read more about this change. The separate Configuration block is gone. Enterprise Library now builds on System.Configuration.

A problem with the 1.0 and 1.1 releases of the Enterprise Library was that these releases didn't ship with roll-over capabilities for log files. Log files continue to grow unchecked. Hisham Baz developed an extension for these versions called the Rolling File Sink. This custom logging sink allows you to set size and age limits for log files. I've blogged about a problem I had with this extension here and here.

Inspired by Olaf Conijn's Enterprise Library Extensions, I decided to create an EntLib 2.0 version of the Rolling File Sink. My version is called the Rolling File Trace Listener. You can find the documentation and the download link for the sources in this article on my blog. The source code and documentation is provided "AS-IS". Feel free to change and/or extend it.

The VS 2005 solution and projects are set up in such a way that is is easy to add additional extensions. They follow the structure of the EntLib 2.0 sources. My extension also comes with a test application to stress test the log file roll-over and the thread safety of the code. It logs 10,000 messages. First from a single thread and after that from dozens of threads simultaneously. Both test cases take a couple of seconds to run. You can edit the app.config file of the test application (either by hand or by using the Enterprise Library Configuration tool) to try out different settings.

One thought on “Rolling File Trace Listener Extension for Enterprise Library 2.0

  1. Hi Erwyn,

    I did extend the sink with some small improvements.
    1. Environment Variable expansion for the file name. So you can configure %LOGDIR%LogFile.txt
    2. ProcessID Expansion to support multi process logging
    LogFile_$PID$.txt which is also expanded.

    3. Call Flush after each write to ensure that all content is written to disk even when a Environment.FailFast() was called to deal with a fatal error inside the CLR.

    Just some ideas to make a good sink even better.


    Alois Kraus


Leave a Reply

Your email address will not be published. Required fields are marked *