Home > Deveploment and Programming, SharePoint Development > How to use Enterprise Library for Logging

How to use Enterprise Library for Logging

In this article,  I am going to show you how Logging Application Block  are used for logging the information to different source.

See the below steps.

Step 1. Download the Enterprise Library 5.0, from the below url


Step 2. Install the Enterprise Library once downloaded.

Step 3. Once install successfully, when you open the web/window application and write click on config file, you can see the below menu(Edit Enterprise library..) to edit the config file.

Click on the menu(Edit Enterprise library..) to edit  the config file.

Step 4.  Once click you can see the below screen

now click on the Blocks menu and select Logging Setting to add Logging application block.

Once  click on Add Logging Setting you can see the below screen.

Step 4.  Just save the config file by clicking File->Save.

And  add the below code in your program and execute the code, by default it log the message in the Event Log.

LogEntry logEntry = new LogEntry();

logEntry.EventId = 200;

logEntry.Priority = 1;

logEntry.Message = “Error Occured”;

logEntry.Severity = TraceEventType.Error;


After executing this code you can check the Event Log and see the message.

Log message in the Text File

Step 5.  Click on the plus sign in front on Logging Target Listeners and click on the Add Flat File Trace Listener.


–          Select Formatter to Text Formatter in the Flat file Trace Listener,

–          Select Listeners Name to Flat File Trace Listener in General  and Logging Error & Warning Section.

Once save the config file, logging will be started at Text file.


Using Enterprise Library, without changing code the log has been maintained to either Event Log, Flat file or Email etc. using this library message can be log in different source as below..

–          The event log

–          An e-mail message

–          A database

–          A message queue

–          A text file

–          A WMI event

–          Custom locations using application block extension points

It simplify the life of programmer to use common and standard function for logging message by maintaining consist approach the practice.



  1. Brijesh
    19/10/2011 at 2:56 pm

    this is good article but here i am facing problem.. while implementing Exception block in class library its give error
    Activation error occured while trying to get instance of type LogWriter, key “”


    • 26/10/2011 at 12:31 pm

      Hi Brijesh,

      Can you please share the code , how you are creating an instance of the class?

  2. Bharath
    02/01/2012 at 2:29 pm

    nice article for beginners.. 🙂

    • Tejesh
      02/02/2012 at 7:34 pm

      Hi Sanjiv,

      Really this is very useful artical, this artical has saved my time.
      if you have created artical for exception handeling in enterprise library 5 then please share.


  3. tejesh
    13/02/2012 at 4:22 pm

    It is very helpful article.
    thanks a lot.

  4. http://fastingforweightloss.net
    19/03/2012 at 12:36 am

    Exactly what I was looking for, thank you for posting.

  5. Eldo
    28/11/2012 at 3:10 am

    This works fine when I run the application on my local machine. But once deployed to the server, it no longer works. What kind of file permission settings that I need to use in the server?

    • 28/11/2012 at 12:24 pm

      I don’t think, it required some special permission on server, did you place binary on server?

      • Eldo
        28/11/2012 at 11:44 pm

        All the Enterprise library dlls are in the server. Also, I have logged into the server machine and after an error, the error was added to the Error.log file. But when I try to access the same server url from my machine, the Error log file is not getting updated.

  6. srijanrawat
    28/07/2014 at 2:10 pm

    where is the trace.log file stored

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: