ActivityID, Tracing and Filenames

Topics: Data Access Application Block
Jul 12, 2011 at 10:45 PM

 

I'm using Enterprise Library 5.0 and Unity 2.0.  I have activity tracing on and am using the Tracer specifying the Category and GUID to use

for the trace.  The trace log consists of all of the entry and exit logs and specifies the activity ID I specified (the GUID).  When other trace information

is written to the same category it outputs the log messages in a seperate file, prefixed with a GUID that does not match the activity ID I specified when

creating the tracer.  Is there a way of using the activity ID I specified when creating the tracer as the GUID used in the prefix of the log file.

i.e  catagory = "Trace" with Listener = "Flat File Trace Listener", filename = "trace.log" OR 7c51dc5d-0a7c-4e40-b46c-f6a0228fae50trace.log.

 

Jul 13, 2011 at 8:25 AM

Hi,

Referring to the source code, it actually creates a new GUID and appends it to the specified file name. The work around I can think of is to extend the rolling flat file trace listener and replace the code that appends the new GUID with your activity id.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 13, 2011 at 3:09 PM

 

Hi Noel,

The code your looking at in the RollFlatFileTraceListener is not the code used to create the files I mentioned (this code appends a GUID to the file name.  The file created when tracing prefixes the filename with a GUID and I cannot locate where this is being done (may be a part of the .net framework).

Question:  Is there a simple way to output trace data to a seperate file for each user connected to a WCF service and to easily identify the file for a user.  This was my intention using a GUID to identify the user and to prefix the trace files with the GUID.  Perhaps I need to just implement something myself.

Thanks

 

Jul 14, 2011 at 11:34 AM

Actually, the GUID thing is a behavior happens when a rolling trace listener instance has the exclusive write access on the file and another rolling trace listener tries to write on that same file. It is briefly explained on this blog. Here is the code:

    try
    {
        this.writer = new StreamWriter(fileNameWithPath, true, encoding1, 0x1000);
        break;
    }
    catch (IOException)
    {
        Guid guid1 = Guid.NewGuid();
        fileName = guid1.ToString() + fileName;
        fileNameWithPath = Path.Combine(folderPath, fileName );
    }

 

The tracer is set to a category that points to a RollingFlatFileTraceListener (when you called the Tracer.StartTrace("CategoryName")) so the writing method is indeed on the trace listener. You can see it yourself if you step through the code. Moving on to your question, I believe this can't be done easily since Tracer is per category basis. One work around I can think of is to use Fluent Configuration API to be able to modify the filename at runtime.

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com
Jul 14, 2011 at 3:45 PM

Thanks for the explanation Noel. I’m using the FlatFileTraceListener which also inherits from TextWriterTraceListener which implements the behavior you mentioned … when a file is locked it prepends the file name with a new GUID.

As for the work around using the Fluent Configuration API … it looks like you could change the filename at runtime … I’m just not sure how well this would work in a service. I’m going to leave the logging as is for the moment and see how things progress.

Thanks for all the help. It’s appreciated.