Rolling Flat File Trace Listener

Topics: Logging Application Block
Dec 5, 2007 at 3:58 PM

I'd like create a rolling flat file trace listener that generates one file for each day of week, therefore, the trace listener will generate 7 files (Monday.log, Tuesday.log, ect.).
Is it possible with Rolling Flat File Trace Listener?? or I need to create a custom trace listener?

Thanks in advance, greetings.
Dec 6, 2007 at 3:49 PM
Rolling flat file listener out of the box, can be configured for each day. But other options are limited, meaning
1. When Rolling File Exists, the trace listener can only Append or overwrite to the existing file. It doest not archive the old file or create a new file.
2. You cannot have a new name for file generated on each day.

To my knowledge, if you need these features, you need to create your own custom trace listener.

Dec 7, 2007 at 7:33 AM
Thank you for your answer NeoAdroit!

So I have to create my custom trace listener... What do you think that could be the best option? Create a trace listener that inherits from RollingFlatFileTraceListener or from FlatFileTraceListener? Are there any example that extends a trace listener?

Thanks in advance, greetings.
Dec 7, 2007 at 1:58 PM
Your custom listener can inherit from Rolling Flat File,as it readily has the logics to roll after a day. Unless you want to do it in a different way. Rolling flat file is indeed derived from Flat file trace listener.

In short, your customRollingFlatFileTracelistener.cs, will have inherit all functionality from Rolling Flat file, and override logic to create a base TraceListener (FlatFile), with a new name. you need to implement a unique file name creation logic here.
You also need to create a customRollingFileExistsBehavior.cs, which will have the actions you need, for example "makenewfile". And you can make use of RollInterval.cs as, you don't need any change in that.

Try Application Block Software factory, that ships with EntLib, Creating a Typed Trace Listener, should help quite a bit in setting up classes.