capturing contextual information using ExceptionPolicy.HandleException?

Topics: Exception Handling Application Block, Logging Application Block
Apr 15, 2009 at 10:45 PM
What is the best way to ensure additional contextual information is captured when using ExceptionPolicy.HandleException?   

My custom IHttpModule has this code:

bool propagateError = ExceptionPolicy.HandleException(originalException, Properties.Settings.Default.ExceptionPolicyName, out newException);

Specifically, when the exception is handled and ultimately logged I want to ensure that the current Request.Path, the user host IP address, and the principal user name are all logged in addition to the exception detail.   I supposed I could hack something together where I jam this information in the Excaption.Data dictionary prior to handling the exception.   Is there a better way to do this using configuration and a custom IExtraInformationProvider?


Apr 16, 2009 at 3:01 AM
Yes you could add those information in the .Data collection property of the exception.  I'm not sure if you could do this in config but I would suggest creating a custom exception handler or using
the helper method from this thread would suffice.  Within the catch block,add those info you need to the Data
property before the call to ExcptionPolicy.HandleException.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.