Rolling flat file never rolls

Topics: Logging Application Block
Feb 2, 2012 at 4:13 PM

 Hi,

I'm testing EntLib5 logging with a rolling flat file. I set it, for the test, to roll every 1KB or 1 minute.
The console application ran for about 3 minutes and wrote a 300KB of log info.

Nevertheless, only one log file was created, with 300 KB size, called rolling.log. It never rolled.
Why didn't the rolling work?

This is the relevant config file settings:

         <add
            name = "Rolling TraceListener"
            type = "Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, ... "
            listenerDataType = "Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData,..."
            fileName = "E:\Temp\rolling.log"
            footer = "&gt;&gt;&gt;----------------------------------------"
            formatter = "Text Formatter"
            header = "&lt;&lt;&lt;----------------------------------------"
            rollInterval = "Minute"
            rollSizeKB = "1"
            timeStampPattern = "dd/mm/yy"
            maxArchivedFiles = "2"/>

Thanks
Sruli

Feb 3, 2012 at 5:47 AM
Edited Feb 3, 2012 at 5:48 AM

The problem is with the timeStampPattern.  The timeStampPattern is used in constructing the rolling file name.  However, you can't use the forward slash as a character in the filename.  Change the slashes to dashes and it should be OK.

If there was a dedicated flat file trace listener for logging errors & warnings (always a good idea!) you would have seen what the error was:

Exception Information Details:======================================Exception Type: System.IO.DirectoryNotFoundExceptionMessage: Could not find a part of the path 'bin\Debug\rolling.03\40\'.Data: System.Collections.ListDictionaryInternalTargetSite: Void WinIOError(Int32, System.String)HelpLink: NULLSource: mscorlib
StackTrace Information Details: ======================================   at 

 

Also, "mm" means minutes and not month ("MM") -- not sure if that was your intent or not.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Feb 5, 2012 at 2:18 PM

Thanks Randy for the quick response. Now the file rolls :)

However, although I asked to keep the last 10 logs, it only keeps the last 2 files.
I added a listner for logging errors, but none was created.
I made several tests with different file sizes, and the result is always the same.

The app.config looks like this:

   fileName = "E:\Temp\rolling.log"
   footer = "&gt;&gt;&gt;----------------------------------------"
   formatter = "Text Formatter"
   header = "&lt;&lt;&lt;----------------------------------------"
   rollInterval = "Minute"
   rollSizeKB = "4"
   timeStampPattern = "dd-MM-yy"
   maxArchivedFiles = "10"
   traceOutputOptions = "None"/>

What's wrong now?

Thanks
Sruli 

Feb 6, 2012 at 6:12 AM

You need to tell Enterprise Library to increment the file names.  The default is to overwrite no matter the number of archived files specified.  Add:

 rollFileExistsBehavior="Increment"

to the configuration and it will save 10 archived files.

--
Randy Levy
Enterprise Library support engineer
entlib.support@live.com 

Feb 6, 2012 at 8:32 AM

Thanks. Now it works.