Logging and emailing exceptions?

Topics: Exception Handling Application Block, Logging Application Block
Oct 11, 2007 at 6:25 AM
How can I log and send email alerts when an exception is caught. I want to log exception to “MyApplicationName” event log and send information of the exception to list of recipients.

I have heard about Error Handling Application Block and Logging application Block but could not find any formal documentation on the object model or good implementation examples. Please help.

Thanks
Oct 11, 2007 at 11:27 AM
Hi,

Have you tried EntLib's help file? You can get it from https://www.codeplex.com/Release/ProjectReleases.aspx?ProjectName=entlib&ReleaseId=4474 if you don't want to install EntLib (be sure to "unblock" the downloaded file to view the content).

The ExceptionHandling-Logging quickstart bundled with EntLib will show a scenario similar to what you are looking for; you should only need to replace the logging config to log to the event log if it doesn't already.

Hope this helps,
Fernando
Oct 12, 2007 at 4:47 AM
hi fsimonazzi

I am unable to open App.Config in C:\Program Files\Microsoft Enterprise Library January 2006\QuickStarts\ExceptionHandling\CS\ExceptionHandlingBasicQuickStart folder with Enterprise Library Configuration tool.

It gives me an error saying “Unable to load assembly ‘ExceptionHandlingBasicQuickStart’. Please copy the assembly file to the tools run directory at ‘C:\Program Files\Microsoft Enterprise Library January 2006\bin\’ and reload the configuration.

???
Oct 12, 2007 at 1:36 PM
Hi,

You need to open the quickstarts' config files with a version of the configuration tool that works with unsigned binaries. This post from Tom explains the situation http://blogs.msdn.com/tomholl/archive/2007/04/19/avoiding-configuration-pitfalls-with-incompatible-copies-of-enterprise-library.aspx.

In general the configuration tool requires all the assemblies referenced by the configuration file to be located in its probing path. The easiest way to do it is to copy the assembly to the tool's folder.

Regards,
Fernando
Oct 13, 2007 at 9:50 AM
Edited Oct 13, 2007 at 9:53 AM
Hi fsimonazzi

Thanks for your reply. It fixed the issue. But now I created a new policy added Exception type and a Loggin Handler to it. Now when I run my application to log the exception I get following error

The type 'Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.LoggingExceptionHandler, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null' cannot be resolved. Please verify the spelling is correct or that the full type name is provided.

???
Oct 14, 2007 at 11:32 PM
Edited Oct 15, 2007 at 5:44 AM
Adding reference to Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll fixed that error!!!

Curious to know few things:

1. How does the application block resolves the path to custom exception handler class?

2. How does EHAB resolves the path to the custom exception handler class?

ExceptionHandlingWithLoggingQuickStart sample calls

ExceptionPolicy.HandleException(ex, "Notify Policy");

from ProcessAndNotify() method of AppService class in ExceptionHandlingQuickStart.BusinessLayer.

How does EHAB works out that “Notify Policy” is defined in a different assembly (App.Config of ExceptionHandlingWithLoggingQuickStart.exe) and it has a custom handler AppMessageExceptionHandler attached to it which is in different assembly (ExceptionHandlingWithLoggingQuickStart.exe).

Exception policies and handlers are defined in the startup app (ExceptionHandlingWithLoggingQuickStart.exe) how are they made available in other layers of the solution? Now if have to reuse a custom handler say in this case AppMessageExceptionHandler in ExceptionHandlingWithLoggingQuickStart.exe in some other project in different solution, then how will I do that?

Is there anyway of learning the internals for EHAB? How, when, which object get initialised etc?

I hope my questions make sense!

Thanks