Five step of how to use logging utility in your projects using application blocks

No.of Views862
Bookmarked0 times
Downloads 
Votes0
By  questpond   On  16 Feb 2010 00:02:29
Tag : ADO.NET , How to
Five step of how to use logging utility in your projects using application blocks
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Table Of Content


Introduction
Step 1
Step 2
Step 3
Step 4
Step 5

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 collected around 400 FAQ questions and answers in WCF, WPF, WWF, SharePoint, design patterns, UML etc. Feel free to download these FAQ PDF’s from my site http://www.questpond.com

You can download my 500 .NET FAQ questionnaire ebook from http://www.questpond.com/SampleDotNetInterviewQuestionBook.zip

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

Thank you

Shivprasad Koirala

 
Sign Up to vote for this article
 
About Author
 
questpond
Occupation-
Company-
Member Type-Expert
Location-Not Provided
Joined date-24 Jun 2009
Home Page-
Blog Page-
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top