RollingFileTraceListener generates filenames with GUIDs

Topics: Logging Application Block
Sep 12, 2012 at 7:13 PM

Hi,

We just started using the logging framwork in our production code.

The following are the relevant settings -

type=RollingFlatFileTraceListener
fileName="\\<server>\<share-path>\%COMPUTERNAME%\RequestLog.log"
rollFileExistsBehavior="Increment"
rollInterval="Day"
maxArchivedFiles="32"
timeStampPattern="yyyy-MM-dd"

What we are seeing in production are the following -

1. Multiple files are sometimes getting created on the same day
2. The older files are being renamed to a pattern like - {GUID}RequestLog.log

We do not want multiple files on the same day.
We do not want the GUID in the file name. We want the older files to be renamed using the TimeStampPattern.

I have verified that when the rollInterval is a "Minute" then the TimeStampPattern is honored. Testing for the day rollover is painful obviously.

So, why is this happening ?

How can we fix it ?

 

 

Sep 12, 2012 at 9:04 PM

What is the actual fully translated fileName you are attempting to write to (e.g. \\mordor\logs\gandalf\RequestLog.log)?  If it has certain characters you may be running into this issue causing rolling to not behave properly.

Also, files are locked so you can only have one AppDomain writing to a file.  Multiple applications (in different AppDomains) on a server cannot write to the same file without causing System.Diagnostics to prepend GUIDs to the file name.

RollInterval of Day corresponds to a Day interval.  This means to roll after 24 hours since the log file was created.  e.g. if the file was created 10PM Monday then the file will not roll until after 10PM Tuesday.  That should result in one file per 24 hour period.  Perhaps you want to roll at RollInterval.Midnight where the file will roll on the next log after Midnight.

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

Sep 12, 2012 at 9:55 PM

The actual translated file path is - \\co2adsaxfile01\DisplayYieldLogs\AvailsLogs\CO2ADSAXAMWEB01\AvailsRequestLog.log. So this should not be a problem given what I understood from reading the link you provided regarding special characters.

We are basically logging the requests to a web method into that file. That web method is part of the SOAP-based ASP.NET web service running on IIS 7 (IIS 7 is configured to be running in compatibility mode of IIS 6).

The service is hosted on a single app-pool on any particular web server. The app-pool is restarted every 20 minutes. Hence there may be a few seconds during which IIS will be killing the old app-pool and starting a new one. Every web service instance (running on the different web servers) will write to its own log file (the machine name is used in the folder path, e.g. CO2ADSAXAMWEB01). Hence across the servers, there should not be any lock contention.

From your statements, it looks like unless there is some sort of lock contention, the GUID should not appear as a prefix to the filename. Is there any recommended way to debug this locking problem ? By design, the contention should not happen in our code. I am wondering what I should do to fix this.

The interval of midnight is a good suggestion. I will get can changed immediately.

 

 

 

 

Sep 13, 2012 at 7:56 AM

Yes, the GUID prefix is caused by file locking issues.  This is done by the .NET Framework in TraceListener implementation.  It definitely sounds like you are having locking issues with overlapped recycling.

You could turn off overlapped recycling.  From How Worker Process Recycling Works (IIS 6.0)

To turn off overlapped recycling, set the DisallowOverlappingRotation metabase property to true.

Of course, that's probably not an option.  Short of that, I can't think of a good way right now to meet all of your requirements.  You could also consider using a Database or MSMQ trace listener which wouldn't suffer from the locking issue. 

To troubleshoot you could Process Monitor to watch the file.

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

Oct 3, 2012 at 4:42 PM

Hi,

we are experiencing same problem with guid in log file names.

Is there a plan to somehow overcome .net TraceListener limitation in future version of the Entlib?

Oct 4, 2012 at 6:54 AM

Since Enterprise Library vNext is in the planning stages now is a good time to post a suggestion (for this or any other ideas!) at http://entlib.uservoice.com/forums/89245-enterprise-library-6-0-unity-3-0.

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