Purge for Logging to Rolling Log File

Topics: Logging Application Block
May 14, 2010 at 7:54 PM

I have been looking for a straightforward way to put together a cleanup method for the rolling log, since it does not perform this for itself.

I figured that I would be able to find the settings for the location of the rolling log via the Logger class, but I don't see any way to get to it from there.

My hope is to iterate through my listeners and find all rolling logs and perform cleanup on the older logs. I know this can be set up in a separate process run by the scheduler, however, it makes so much sense for this to be integrated, so that any and all implementations of my logging class know that cleanup is done as configured for them.

Is there a way to read the configuration through the Logging AB classes or do I need to open up the configuration myself and read it?

May 17, 2010 at 12:45 AM

If you're using entlib 5.0, the rolling flat file trace listener now has a new property named Max Archived Files which you can set to any integer value denoting the maximum number of files to retain.  If the value is reached, it will automatically purge the old files. 

However, if you're using a lower version, there's no support for this.  You would read the logging block manually by retrieving the LoggingSettings object from the config.  However, I don't see a straightforward way of looking up the filenames of the files that has been archived by the rolling flat file trace listener.  I think you're going to make assumptions on their filenames.  A cleaner implementation would be to create a custom trace listener that mimics the RollingFlatFile Trace Listener but has the facility for deleting those old files.


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.