logging using enterprise library application

Topics: Exception Handling Application Block, Logging Application Block
Feb 9, 2010 at 8:38 AM

Dear all,

I am totally new to enterprise library. I need to create an exception module which need to log the exception to flat file, event log, database and email as message in different situations. Can any one help me by telling how to proceed in my task. Do i need to create a table in my database to log the exception?



Feb 9, 2010 at 9:36 AM


What do you mean by different situations? Do you have different scenarios for this one?

Since you are new to ent lib, I encourage you to read the documentation first, there are some available walkthoughs that will help you in configuring a block for a specific task. You might also want to try the quickstart applications that comes with ent lib. It is available when you install the source code. It is usually in <DriveLetter>:\EntLib41Src\Quick Starts. There is also the ent lib hands-on-lab which is available via this link http://entlib.codeplex.com/wikipage?title=Hands-on%20Labs&referringTitle=Home .

For your task:

You would need to configure the exception handling application block.

  1. Add a new exception policy
  2. In your policy, add a exception type
  3. In your exception type, add a Logging Handler
  4. Configure your logging handler and point the LogCategory property to the category.

To log to a flat file:

  1. add a flat file trace listener on the tracelisteners section of the Logging Application Block.
  2. add a category where you want to associate the flatfile trace listener or you can use the default category which is the "General" category
  3. add a trace listener reference on the category that you've created and point it to your flat file trace listener

NOTE: The same steps also applies to the event log and email.

For the database:

  1. First execute the script that will create the logging database, it is available in <DriveLetter>:\EntLib41Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts
  2. In your config, Configure a new connection string and point it to the logging database (This one is in the DAAB section)
  3. In the logging block section, add a database trace listener
  4. Configure its properties specially the Database property and point it to the connectionstring that you made in step 2
  5. add a trace listener reference on the category that you've created and point it to your database trace listener

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.

Feb 9, 2010 at 10:34 AM

Thanks a lot Valiant Dudan... I shall first go through the documentations and the quick start applications.

Feb 10, 2010 at 10:06 AM


I have almost succeded in writing log to flat file and database. Could you explain in detail how to write information to a email message? Also while writing to database I created the database with the script available in <DriveLetter>:\EntLib41Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts. Can I use my own database for this purpose?


Feb 11, 2010 at 4:47 AM

Yes, you sure can use your own database.  If you will just copy the tables and stored procedures from the Logging database, then you only need to point the connection string to your own database.  If you're going to modify something in the schema, that entails creating your own custom database trace listener as well. 

"Could you explain in detail how to write information to a email message?" - Are you referring to the message body of the email message?  If yes, then you just need to put whatever you want in the Message property of a LogEntry object. 


Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.