Wednesday, April 25, 2007

Set up the Database Trace Listener in Enterprise Library.

I am getting very interested in Microsoft Enterprise Library lately for a couple of reasons:
  • It addresses a couple of common issues you will normally face, like logging, caching, and you really don't want to do those plumbing code if possible.
  • It gives you a nice configuration tool ( you can open this tool within visual studio for the Enterprise Library 3) .
  • It gives you all the source code, so you can see what's under the hood.
I am playing with the Logging application block in last two days, the best way to learn those tools is always to check the QuickStart source code. I found the quick start doesn't provide an example to show you how you can log the error into the database, which I believe is the most used cases in the system.

I did a brief research, and you actually have to reference another dll (Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll) in order to be able to log into the database.

Basically, you have to do the following steps :
1. The "Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll" has to be referenced.
2. The scripts under "C:EntLib3SrcApp BlocksSrcLoggingTraceListenersDatabaseScripts" has to be run against the database to create the necessary tables and objects.
3. The "Database Trace Listener" has to be added to the "Trace Listeners". For the trace listener, you have to specify the Formatter, otherwise, you will get an error.
4. Put the "Trace Listener" under the Category you want to log.

Here is a screenshot of the configuration file..


No comments: