Logging Insight

Topics: Logging Application Block
Aug 17, 2009 at 2:31 PM


I'm pretty new to logging application block. I'm kinda interested in using logging block to log in a database. Any of you guys got any insights or points that will help me achieve this? Also I would like to extend the columns that was provided in the scripts that was from the ent lib source. Any ideas are welcome.


PS: I'm also looking at the policy injection to be used together with the logging block, so you can also add to that. thanks.



Aug 18, 2009 at 5:22 AM


First off, what you would need to do is:

  1. Create your custom table (with your desired columns) where the logentries will be logged.
  2. Create your custom stored procedure that will add the logentries to your custom table.
  3. Create a custom Log Entry class that inherits from the logentry. NOTE: this will encapsulate the value for your additional column. Say, you've added a column "LoggedUser" (which logs the name of the currently logged user.) Your class will look like this:
        public class MyOwnLogEntry : LogEntry
            public string LoggedUser { get; set; }
  4. Then you will now create a custom trace listener, this custom trace listener will be the one responsible for sending the logs to the database. Please refer to this: http://msdn.microsoft.com/en-us/library/cc511727.aspx to guide you creating a custom trace listener. You just need to implement a code that will save the logs to the database. You can try viewing the FormattedDatabaseTraceListener class in the ent lib source code for your reference.

Related Post:



Valiant Dudan
Global Technology and Solutions
Avanade, Inc.

Aug 18, 2009 at 8:20 AM

To add to your question about PIAB and LAB, please see these links: