Logging to database

Topics: Logging Application Block
Mar 2, 2011 at 5:03 AM

Hi ,

Can you please explain how these tables are related and useful







Mar 2, 2011 at 7:30 AM

The Category table contains entries for each category defined in your logging configuration.  The Log table contains the information itself of the LogEntry object from your code.  This table references the Category table which enables you to group log entries by categories.  The CategoryLog table represents each category to which a specific log entry belongs to. 

For example you have this LogEntry object:

LogEntry log = new LogEntry();
log.Message = "test logging";

Your Category table will have 2 rows; one for the Informational category and the other one for the General category.  You Log table will then have one row containing details of the LogEntry object.  The CategoryLog table on the other hand will have 2 rows, both references the row from the Log table as indicated in the LogID column and each row relates to the Category table using the CategoryID column.  If your LogEntry object is only associated to the Information category, then the CategoryLog table will only have one row added to it.

Honestly, so far I'm only actually dealing mainly on the Log table but there may be scenarios where you might need the information from the Category and CategoryLog table.  That would be probably mostly for purpose of categorizing the logs written in the database.


Sarah Urmeneta
Global Technologies and Solutions
Avanade, Inc.