Why exception is logged into a separate flat file?

Topics: Data Access Application Block, Logging Application Block
May 11, 2007 at 1:29 PM
When I try to log events into a flat file everything works ok except logging exceptions which are always written in a separate file with name <guid>.log.
Is there any option to chacnge this behaviour and write the exception messages into the same log file?
May 12, 2007 at 12:27 AM
This has to do with the TextWriterTraceListener in the .NET Framework. If an attempt is made to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID. I believe the exception handling logger tries to access the log file that is in use by the logging block and the TextWriterTraceListener creates a new file with a guid under the covers.

I don't know of a way around this.

Regards,

Dave

________________________________

David Hayden
Microsoft MVP C#
May 14, 2007 at 1:48 PM

DavidHayden wrote:
This has to do with the TextWriterTraceListener in the .NET Framework. If an attempt is made to write to a file that is in use or unavailable, the file name is automatically prefixed by a GUID. I believe the exception handling logger tries to access the log file that is in use by the logging block and the TextWriterTraceListener creates a new file with a guid under the covers.


Hmm... this is pretty strange. I have a single Flat File Trace Listener in my config file and I was under impression that ALL log/error messages go trough a single trace listener.
Is it feasible to log both log messages via LAP and errors via EHAP into the same flat file?
May 14, 2007 at 3:41 PM
I agree it is pretty strange. I duplicated it during a quick test but never came acrossed it in production as I don't use the flat file tracelistener.

I asked one of the developers about this but haven't received a response yet. I will get back to you as soon as I hear from him. Or, perhaps someone else who uses the logging block in this scenario knows why it occurs and how to solve it.

Regards,

Dave

__________________________________

David Hayden
Microsoft MVP C#
May 14, 2007 at 5:15 PM
Unfortunately this appears to be a problem based on what I mention above with regards to the behavior of the TextWriterTraceListener.

I created a Work Item for it: http://www.codeplex.com/entlib/WorkItem/View.aspx?WorkItemId=10278 as this is indeed a strange problem.

The best bet now is to use separate tracelisteners or the Distributor Service as mentioned in a few other posts recently:

http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=9889

http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=9552

http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=9510

Regards,

Dave

____________________________

David Hayden
Microsoft MVP C#
Jun 1, 2007 at 7:17 PM
Question:

I have run into the same problem with the exception/logging blocks being combined, and, the solution to use the distributor works fine.

My question is this: if there are several applications running on the same server that the distributor service is running and they all want to log messages and exceptions to a separate log file for each - how can this be accomplished via the distributor?

Correct me if I am wrong, but it appears to me that the distributor is looking only at one message queue, and, based on the context of the message, will then route it to the correct log file trace listener. Does this mean that each application using the logging/exception should apply a prefix to their context messages so that they get routed to a separate file?

I am posting this here since I feel that it relates to this issue.