It took me a while to find out the (very simple) solution to my problem, so I thought it would have been a good idea to create a post explaining it.

The problem

I’m logging from my application using Enterprise Library Logging component, and I wanted to have a new file every day. So I configured the logger with the RollingFlatFileTraceListener. One of the properties you can specify during the registration is the rollInterval attibute, which configures the log to roll every minute, hour, day, week, month, year.

I wanted to have a new file every day, so I specified “day”: I got a new file per day, but the rolling was happening at “random” times during the day. Actually it was not really random: the rolling time was moving forward by a few minutes every day.

The solution

After looking around and finding nothing I looked by mistake at the docs of v5. They said:


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.

The need of rolling is calculated before performing a logging operation, so even if the thresholds are exceeded roll will not occur until a new entry is logged.

Both time and size thresholds can be configured, and when the first of them occurs both will be reset.

The elapsed time is calculated from the creation date of the logging file.

Here everything is explained: the elapsed time is a day from the creation of the file, and the actual moment in which the new file is created is the next log entry after that 24 hours.

I also found out that the rollInterval property is based on an enum, RollInterval,  which contains also another element that I had previously overlooked: Midnight. This makes the file to roll at the beginning of each day, instead of every 24 hours.