DCSIMG
How to control the naming and sizing of Logging application block flat file listener - Pini Dayan

Pini Dayan

The best thing about a boolean is even if you are wrong, you are only off by a bit.

How to control the naming and sizing of Logging application block flat file listener

Hi all, I have been working lately on building this infrastructure framework for the following services:

  • Data access.
  • Logging.
  • Exception management.
  • Security
  • Caching.

Some of the services i have built are built on top of the Microsoft Enterprise Library version October 2008 (version 4.1). One of the things that bugged me when i implemented the Logging mechanism on top of the Logging Application Block was that i cant control how log files are spread and created. Flat file trace listener and Xml file trace listener simply write to the given file name. This file sometimes need to be viewed (lets say by a parser or viewer i have built) and since this file may grow uncontrolled, i wanted to found a way to "roll" this file into many files according to lets say: The date the file was created or the size of the file.

As it turned out there is a very simple solution.Simply use the Rolling file trace listener.

From the Microsoft Enterprise Library documentation: "Performs logging to a file and rolls the output file when either time or size thresholds are exceeded".

and:

Logging always occurs to the configured file name, and when roll occurs a new rolled file name is calculated by adding the timestamp pattern to the configured file name.

Here is how to configure this trace listener:

1. Create under the Logging application block node for your project configuration the following listener:

image

2. Now configure the file age and the file size you thresholds you want:

image

3. Here are some of the thresholds properties you can configure:

Size Threshold:

You can limit log file growth based on file size.All you need to do is configure the "RoleSizeKB" property to the wanted size in KB. Once the size has elapsed the new file name will be some GUID + the name of the file.The default is zero so make sure you don't leave it this way.

Age Threshold:

The age threshold needs to be configured 1 property, The RolInterval(can be set to Day, Month , Year etc) .

Comments

*** said:

Where is the Age Threshold? I don't see it in your screenshot...

# September 16, 2010 12:39 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: