SharePoint / ASP.Net Development
Experiences from the field...
Navigation
   RSS 2.0
Categories
Entries by Month

# Tuesday, March 09, 2004

Kirk Allen Evans:

A Better ExceptionXmlPublisher for the Exception Management Application Block. This snippet incorporates part of a post from microsoft.public.dotnet.framework.  It shows how to allow multiple threads to write to the same file at once, using a mutex to provide concurrency.  This example is integrated with the Exception Management Block to provide a means of logging errors in multi-user applications to XML files.

I use the EMAB as well to log to a file. I need to put this mutex code in my solution -- Thanks Kirk. However, the log file in Kirk's example may not be well-formed. He is appending exceptionInfo.OuterXml to the file each time. My version: ExceptionPublisher.htm

Tuesday, March 09, 2004 1:52:22 PM (Central Standard Time, UTC-06:00)  #    Comments [2]  |  Tracked by:
"consumer report on diet pill" (consumer report on diet pill) [Trackback]

Tuesday, March 09, 2004 3:02:48 PM (Central Standard Time, UTC-06:00)
Nice job.

The difference between implementations is that your solution overwrites the last entry (due to the use of FileMode.OpenOrCreate). I see merit in both approaches.

I had actually considered making the log file well-formed when I wrote the post last year. The problem is that it would take up too many cycles to seek to the end of the stream minus the position of the </log> element while taking into account different encoding offsets.

XmlReader can be used to read an XML fragment, or you can append a root node to the log XML document before reading it. In fact, this is what you have to do when using SqlCommand.ExecuteXmlReader using SQL Server's FOR XML clause because FOR XML does not necessarily return well-formed XML. I chose the approach of putting the burden on the reading application rather than put the burden on the logging implementation.
Tuesday, March 09, 2004 9:43:37 PM (Central Standard Time, UTC-06:00)
I don't overwrite the last entry, I overwrite the entire file. That probably takes even more cycles. :) I like your decision about putting the burden on the reading app. Thanks!!!
Paul Schaeflein
Comments are closed.
Search

Further Reading...

Powered by: newtelligence dasBlog 2.2.8279.16125

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008, Paul Schaeflein

Send mail to the author(s) E-mail