Working through custom trace listener example

Topics: Building and extending application blocks, Exception Handling Application Block, General discussion, Logging Application Block
May 22, 2010 at 12:02 PM

Hello all,

I have requested and am working through the custom trace listener example mentioned here:

I have a couple questions:

1. In the sample code, this method is called to execute the stored procedure: ExecuteAddCategoryStoredProcedure - I want to also include all of the parameters already setup by the Database Trace Listener. Is there a way to call into Database Trace Listener to get its command object and then just add my custom parameters to its parameter collection? Or do I need to populate them all myself?

2. Do I also need to implement a custom TextFormatter for the added properties to be able to show up as tokens

3. I found the following code in another thread about CustomTraceListeners - what is it doing and where does it go
   if (Formatter != null)
       db.AddInParameter(cmd, "formattedmessage", DbType.String, Formatter.Format(log));
   else
       db.AddInParameter(cmd, "formattedmessage", DbType.String, log.Message);

May 24, 2010 at 2:38 AM

1.  You would need to populate them all yourself because the methods in the FormattedDatabaseTraceListener which does this includes the call to ExecuteNonQuery right after adding the parameters.

2.  You cannot add items in the tokens dropdown list without modifying the source code.   But you can specify your own custom token using the keyvalue token.  For information on how to do this, please refer here- http://entlib.codeplex.com/Thread/View.aspx?ThreadId=7636

3. It's actually just copied from the code of the FormattedDatabaseTraceListener.  It's just using the formatter specified for the tracelistener to convert the contents of the logentry object according to the formatter's specification.  If not, it just uses the content of the Message property of the logentry.  Whichever value it is, it goes to the FormattedMessage column of the Logging database.

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