CODEDIGEST
Home » Articles
Search
 

Technologies
 

Sponsored links
 

CodeDigest Navigation
 

Technology News
No News Feeds available at this time.
 

Community News
No News Feeds available at this time.
 
Using Logging application Block in Enterprise library 4.0 - Step By Step

By ShivPrasad Koirala
Posted On Oct 03,2008
Article Rating:
Be first to rate
this article.
No of Comments: 5
Category: ASP.Net
Print this article.

Using Logging application Block in Enterprise library 4.0

 

Introduction

It’s new world of software reusability. Gone are the days when we need to build things from scratch. One of the most needed functionality is the logging utility. Every software project needs a logging utility. To make your own logging utility is a big project by itself.  In this tutorial we will quickly run through how you can use Microsoft logging application blocks to log messages and activities.

You can log your errors or debug messages to the following sources using logging application blocks:-

 

Ø       Event log

Ø       Email

Ø       Database

Ø       Message queue

Ø       Write to text file

Ø       WMI events

Ø       Custom locations using application block extension points

 

I have been writing and recording videos for architectures. I have uploaded some sample videos for design pattern,UML,Function points  here. . You can visit http://www.questpond.com and download the complete architecture interview questions PDF which covers SOA, UML, Design patterns, Togaf , OOPs etc.

 

You can download my 500 .NET FAQ questionnaire ebook from here

 

Step 1

Create a new project with a simple button on the ASPX page. Let’s name this button as btnlogger. What we will do it when any one clicks on this button we will log a error message in the event log.

 

Figure :- Simple project

 

Step 2

 

Download the Enterprise library 4.0 from http://www.microsoft.com/downloads/details.aspx?FamilyId=90DE37E0-7B42-4044-99BE-F8ECFBBC5B65&displaylang=en . Once you install it you should see the same in programs – Microsoft patterns and practices.Click on open and browse to your web.config file and click the open button.

 

 

 

Figure :- Enterprise library installed

Figure :- Open the web.config file

 




Step 3

All your logging facility is stored on the web.config file. Now right click on the tree , click new and click logging application block menu.

Figure: - Add logging application block

 

Step 4

By default the logging utility logs to event logs. So you will see in the trace listeners a event log trace listeners already added. Click on the event log trace listeners and specify the machine name. Currently my machine name is HP.

Figure:- Specify machine name

 

Step 5

Now that we have defined the necessary configuration using the logging enterprise tool. It’s time to call the same in the code. So we add the Enterprise logging application DLL , add the logging namespace , create object of ‘logentry’ object and finally log the message using the logger DLL.

 

Figure: - Use the logging application block

 

Now if you run the program and click the button you should see the message logged in event viewer. To view event viewer click on start , run and type eventvwr.

 

Figure: - Logged in the event viewer

 

 

Conclusion

Error logging is an important module in most of the enterprise applications we develop. Understanding this importance Microsoft released a logging application that is very well proved and optimized for performance. This article gave us a simple walkthrough to use in our application.

 

Similar Articles
You can contribute to CodeDiget.Com:
Donate to CodeDigest.com
Article Feedback
Comments
Article Feedback
Hi ShivPrasad,

Thanks, The article is pretty usefull..
Image sizes
article is very good. easy to understand .thanks for the post.
Images are not displyaing properly. you might provide link to full image.
yup
no detailed description
Screen Shots
Dude, your screen shots are unreadable. Please use the snipping tool or snippy.exe and cut only the relevant portions of the screen
Thanks!
Nice Walkthrough!