[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


Enterprise Library Logging Configuration

Published on
11,522 Points
Last Modified:
Community Pick
Here is the example of setting up enterprise library configuration in asp.net.

One of the great enhancements that comes with the Enterprise Library is the Enterprise Library Configuration Console. This can be found on your Start menu under Program Files > Microsoft patterns & practices > Enterprise Library. With the console, you can use a fairly user friendly GUI to edit the various configuration files.

Here I am trying to make you understand this feature, by keeping one thing in my mind that “An Image can express thousands words”.

First of all, I download the Enterprise Library and Installed on my computer.

Now open “Enterprise Library Configuration Console” and open Web.Config using its File menu. And this will show your settings here, whatever you have written in you config file.


Now under “Data Access Application Block”, you will find that its must be showing you the connection string you defined in Web.Config file, if you have not created any connection string yet, then you can add this here too.

This is my database, where I have place 3 default tables for handling errors.

And these are stored procedures that are used for the entering data into tables.

So my connection string will look like something like this.

Now here, I add “Exception Handling Application Block”, you may find other lots of other stuff, but we are just concentrating on catching up errors in our database here.

Now under the “Exception Handling Application Block”, I create “Exception Policy”. You can add multiple policies under this block.

Now against each policy I can add “Exception Type”, now it’s up to you what kind of exception type you would like to choose for this policy.

Here we are selecting generalized “Exception” to catch all kinds of errors.

Now we change post handling action to none, this action determines what action should occur after an exception is handled by the configuration exception handling chain. None indicates that no post handling action should occur.

Now we add a logging handler to the system for the same exception we just crated.

And you will see that after adding logging handler it will automatically add “Logging Application Block” to the console.

Now go back to logging handler, and choose the Formatter Type for exception. Formatter Type is basically a format to display the exception.

And here we select the text formatter to display the exception.

After selecting the formatter type, we change some another setting as well, like we add some category under Logging Application Block --> Category Source. We can add multiple categories, i.e. Database, Email. And then we choose any category for this handler.

Now we add “Trace Listeners “, We can choose based upon the requirement, in case you need to send error email then choose ‘Email Trace Listener’. Here we are handling exception in database so we choose ‘Database Trace Listener’

Now you will find that ‘Database Trace Listener’ contains some default properties. It automatically has the procedure names to add Category in the database. All categories that you have created and linked will be added to the database automatically.

Now we change its properties, and we select database instance, formatter and Trace Output Options as shown in the below image.

Now under special sources, we have three different sections, 1st is Logging Errors and Warning, 2nd is Unprocessed Category and 3rd is All Events. For all three sections we add Referenced Trace Listener. Also we change its reference to ‘Database Trace Listener’.

This is all what you have to do, here is the references I added to my application. I am not sure all references were added, so please cross check yourself, I hope you can do this at least

And here is my code, where I am trying to raise the error, and please note that I have used the same policy that I created in console.

And this is the output in all 3 tables.


Featured Post

Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Join & Write a Comment

Overview of OneDrive and collaboration.
Please check the video also in regards to recovery of deleted emails from office 365 admin center and through the MFCMAPI tool. I have mentioned each and every step with the proper steps that need to be taken care of.

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month