Search code examples
.netasp.netloggingexceptionenterprise-library

Enterprise Library Exception Handling Application Block and Logging Application Block proper use in ASP.NET


I have a grasp on this application block with ASP.NET, but I feel unsure if I am coding with it properly in ASP.NET.

I've looked all over for proper examples of how to use the Enterprise Library Exception Handling Application Block, but only turn up articles for Windows Forms.

Could somebody please point me in the right direction for usage of the Enterprise Library Exception Handling Application Block with ASP.NET? (e.g. handling exceptions in classes, when to propagate exception to Application_Error in Global.asax, how to process handled and unhandled exceptions in Application_Error).

I would really like to see what other people are doing.

Code incorporating the Enterprise Library Error Handling Application Block with the Logging Application Block would also be helpful.

Thanks!


Solution

  • Handling exceptions with the ELEHAB is basically the same in all types of application. You catch the error and call ExceptionPolicy.HandleException. The only difference is exactly where you put your "global" catch block. In WinForms, you might put it in the Main method. In ASP.NET, you might put it in the Application_Error event. In a Windows Service, you might put it in the background thread start method.