Tuesday, September 4, 2007

Exception Handling .NET 2.0 - Microsoft Enterprise Library

There are lot of advantages if you use Exception Handling mechanism provided by Microsoft Enterprise Library for .NET 2.0 Framework

1. You can download the MSI Installer of Application Block for Exception Handlers from

http://www.microsoft.com/downloads/details.aspx?FamilyId=5A14E870-406B-4F2A-B723-97BA84AE80B5&displaylang=en

The exception handling will catch the exceptions and make the developer to view as text file/ view the exception from event viewer of the system.

2. Add references to three DLLs to your project

Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll

to your bin folder of your project.

Import the namespaces into your project

C#

using Microsoft.Practices.EnterpriseLibrary.Logging;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging;
using Microsoft.Practices.EnterpriseLibrary.ExceptionHandling;

VB.NET

Imports Microsoft.Practices.EnterpriseLibrary.Logging
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling

3. Wherever you have your catch blocks in your aspx page make this alteration

C#

catch (Exception ex)
{
ExceptionPolicy.HandleException(ex, "Log Only Policy");

}

VB.NET

Catch ex As Exception
ExceptionPolicy.HandleException(ex, "Log Only Policy");

"Log Only Policy" ----> Is the key value which will be coming from web.config

4. In order to catch exceptions in event viewer, please follow these settings



Go to Web.config

Step 1 :



Step 2 :



Step 3 :





Above steps will make the error available in your Event Viewer.

To see event viewer error logged, go to start-settings->cotrol panel->Administrative tools->Event viewer-Application->Logged Error.

For assistance, feel free to email @ sharpeye500 at yahoo dot com

3 comments:

neovins said...

where are you from copy pasting this ?

seems to be copy paste error ...

Karthick said...

I donot copy & paste anything from anywhere...

I just copy from my brain & paste in my blog.....

Unknown said...

Hi,
Getting the following error message when replicated the above specified code in my app. Plz help me out to solve this

"Unrecognized configuration section exceptionHandling"