Changing EventID when using LoggingExceptionHandler

Topics: Exception Handling Application Block
Jan 7, 2007 at 5:07 AM
I declared a LoggingExceptionHandler in my ExceptionHadling block. The logging exception handler writes to a file.

In code, i try to change the EventId, and i get exception with the message "The configuration is read only".

This worked in the previous version of entlib, but stoped working with entlib Jan2006.

Is there a way to change the eventId in runtime ?
Jan 19, 2007 at 3:34 PM
Can you show the code for EntLib 2.0 where you try to change the EventID during runtime?

The EventID is specified by you in the app.config or web.config when you are adding the LoggingHandler to the Exception via the Configuration Tool.

This value is then passed to the LoggingExceptionHandler Class in its constructor and the private member is set as ReadOnly, which would suggest you cannot change it.

If you are trying to pass additional runtime data to be logged with the exception, you can add it via the Data Collection of the exception class. This data gets passed to the logwriter in its ExtendedProperties collection and displayed in the log.

catch (NullReferenceException ex)
// Add Some Run-Time Information
ex.Data.Add("Note1", "Some note...");
ex.Data.Add("Note2", "Some note...");

ExceptionPolicy.HandleException(ex, "LoggingPolicy");

Other than creating the LoggingExceptionHandler Class directly, I don't know of a way to change the EventID at runtime. Adding additional data to the Exception as mentioned above, however, may meet your needs.




David Hayden
Microsoft MVP C#