Click here to Skip to main content
Click here to Skip to main content

Five steps to using a logging utility in your projects using Application Blocks

, 5 Mar 2014
Rate this:
Please Sign up or sign in to vote.
Steps to use a logging utility in your projects using Application Blocks.

Table of Contents

Introduction

It’s a 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 we 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 on Design Patterns, UML, and function points at http://www.questpond.com/FreeDesign1.htm. 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 http://www.questpond.com/SampleDotNetInterviewQuestionBook.zip.

Other Application Blocks

  • Validation application blocks: This article explains the 16 steps you need to perform to do validations using VAB: Validation application blocks.
  • Client side validation: One of the shortcomings in VAB is that it does only server-side validations. This article talks how we can leverage VAB for client side: Client side validation.
  • Policy application blocks: This article talks how to implement a plug and play mechanism using Policy application blocks: Policy Application Block
  • Data application: This article talks about the four steps you need to implement data application blocks: Data application block.
  • Exception application block: This application talks how we can use exception application blocks to log exceptions from projects: Exception application block.
  • Unity application block: This application talks about Unity Application Block in DI and IOC: Unity application block.
  • UIP block: This article talks about reusable navigation and workflow for both Windows and Web using Microsoft UIP blocks: UIP block.

Step 1

Create a new project with a simple button on an ASPX page. Let’s name this button btnlogger. What we will do is, when anyone clicks on this button, we will log an error message in the event log.

Figure: Simple project

Step 2

Download 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 the 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 an event log trace listener 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 an object of the 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 the event viewer. To view event viewer, click on Start, Run, and type eventvwr.

Figure: Logged in the event viewer

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Shivprasad koirala
Architect http://www.questpond.com
India India

I am a Microsoft MVP for ASP/ASP.NET and currently a CEO of a small
E-learning company in India. We are very much active in making training videos ,
writing books and corporate trainings. Do visit my site for 
.NET, C# , design pattern , WCF , Silverlight
, LINQ , ASP.NET , ADO.NET , Sharepoint , UML , SQL Server  training 
and Interview questions and answers


Comments and Discussions

 
GeneralMy vote of 3 PinprofessionalJV99997-Mar-14 1:24 
GeneralMy vote of 3 PinmemberaTIF_SATTI_00723-Dec-11 2:31 
GeneralMy vote of 1 Pinmemberwegenerb23-Mar-09 4:21 
GeneralNeed more PinmemberMark Nischalke21-Oct-08 1:05 
GeneralMore detail needed PinmemberCIDev1-Oct-08 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140821.2 | Last Updated 6 Mar 2014
Article Copyright 2008 by Shivprasad koirala
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid