Custom Database Trace Listner

Topics: Logging Application Block
Jan 14, 2009 at 7:06 PM
Edited Jan 14, 2009 at 7:17 PM
Hi,

Unlike normal trace which logs a string, I want to pass data as few parameters to database. Is that a good idea to extend existing Tracing infrastructure??

instead of  "Trace.Write("some string");
I would like to pass it as "Trace.Write("TestMethod","Somestring",DateTime)


I would appriciate if any one can point me in the right direction...


Thanks...


Jan 15, 2009 at 9:35 AM
You mean extend the FormattedDatabaseTraceListener class? Yes, if you need extra parameters, that's the way to go.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 16, 2009 at 8:44 PM
Thank you for your response..

I spent some time online to browse through some articles on extending FormattedDatabaseTraceListener . I was able to get more insights in the process. I have few more questions to straighten things out

1. I have seen two ways to extend Trace Listeners. Should I be extending from "CustomTraceListner" or "FormattedDatabaseTraceListener " or "FormattedDatabaseTraceListener ".

2. I see that currently we are formatting the input in to single string parameter that needs to logged in to database. Could please provide more information on the points of extension if I need to have different parameters ( ex: Trace.Write takes one parameter and remaining are gathered and passed on to database.. what if I want to gather more information from Trace.ex: Trace.Write (param1,param2,param2)

3. If I extend from "FormattedDatabaseTraceListener" will I be able to use the in built configuration capabilities of Enterprise Library (i.e controlling settings from config  files)

It would really help me if we have any samples or guidance..


Thanks,...

Jan 17, 2009 at 3:51 AM
Edited Jan 17, 2009 at 3:58 AM
Hi,

I think the easiest way to Log to database with custom properties is to create your own custom trace listener.

Create a custom trace listener:
http://msdn.microsoft.com/en-us/library/cc511727.aspx

Just like this one:
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=44101


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 17, 2009 at 4:03 AM
1 and 3. I suggest you inherit from the CustomTraceListener in order to use the configuration capabilities of EntLib.
2.  There are a lot of methods you can override in the CustomTraceListener object.  One that would be helpful would be the Write(object o) method.  You could create a custom log entry that will contain the information you need to log to the database and pass that to the Write method.  Just cast it to your custm log entry inside the method.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com
Mar 28, 2011 at 2:37 PM

Hi Sarah,

I am using IBM DB2 database and Ent Lib 5.0. I want to log to IBM DB2 Database using Ent Lib Logging application block. Could you please provide a sample working code or point me to a resource or a link.

 

Much Appreciated

Thanks,

Rahul

Mar 29, 2011 at 1:27 AM

I have posted my answer in the other thread.

Please create a new discussion for a different issue.

 

Sarah Urmeneta
Global Technologies & Solutions
Avanade, Inc.
entlib.support@avanade.com