Store LogEntry on DB | Properties -> Columns

Topics: Logging Application Block
Feb 7, 2008 at 11:51 AM

Is there an inbuild way in Enterprise Library 3.1 to log a LogEntry to a database, splitting each property of the LogEntry object into its own column?

LogEntry logEntry = new LogEntry();
logEntry.Title = "Title";
logEntry.Message = "Message";
logEntry.Priority = 1;
logEntry.ExtendedProperties.Add("File", @"C:\File.xml");
logEntry.ExtendedProperties.Add("ExecutionTime", new TimeSpan(1,0,0));


Eg. The above piece of code would put a record in table “Log” etc, with “Title” in a column called Title and “C:\File.xml” in a column called File?

If not, does anyone have any recommended ways to achieve this?

Feb 29, 2008 at 10:06 AM

Looking at this right now myself. One way would be to take the FormattedDatabaseTraceListener (within Logging.Database) as a template and write your own custom listener. This listener might require having another stored procedure besides WriteLog, say WriteExtendedProperties, that writes to a new table (with name and value fields). It would mean more db writing but give you the benefit of detailed reporting on specific errors and logging any valuable user info before it might be lost. This new table approach of name and value would be very flexible as you could just add more extended properties at any time and you'd know the listener would deal with accordingly. Of course, this approach would work on having strongly typed column fields like "ExecutionTime" but this would mean you are tightly linked there. Benefit of this is better tuned db but if you wanted to start logging more properties you'd have to edit your listener and database every time. Trade-off situation.

This is not too difficult but neither trivial, looking around here to see if any has done something similar. Will let you know what i do.

Feb 29, 2008 at 10:06 AM
Edited Feb 29, 2008 at 10:06 AM
duplicate (deleted)