Debugging a DB trace log listener

Topics: Logging Application Block
Aug 6, 2010 at 8:11 AM

I tried to add a database listener, but it seems that either the stored procedure I call fails, or it never gets called.

I've tried to test the stored proc, and it works.

I have tried to use another stored proc, and that works.

I've been messing a lot around with the stored proc params and the text formatter to make things as simple as possible.

I still haven't found the bug yet, so now I ask you gurus:

How do I debug this so I can get myself some sort of errormsg to solve the problem? Thanks in advance.


Aug 6, 2010 at 8:33 AM

You can configure a trace listener under the Logging Errors and Warnings section.  When an error occurs while logging, a message will be sent to that trace listener logging information about the exception that occurred. 

If you didn't get enough information based on what is logged by that trace listener, you can download the PDB files for the version you're using here in Codeplex.  It will enable you to debug and step into entlib's source code. For instructions on how to use it, refer to this thread.  The 5.0 version though, doesn't have the PDB files released yet.  


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Aug 6, 2010 at 9:11 AM

So if I get it right: If I run v. 5, then I can't debug yet?

Any other suggestions?

I think it is a bit weird...I have two working listeners and one that doesn't. All the stored procs work. I wonder if there's something I need to do differently. Or maybe a good article about the text formatters and their syntax. Maybe I've done something wrong.

I've tried to make it VERY simple:

Timestamp: {timestamp}{newline}

And the sp has

@Timestamp datetime = NULL,

@LogId bigint OUTPUT

as params.

Aug 6, 2010 at 9:18 AM

Did you try my other suggestion?  (Configuring a trace listener under the Logging Errors and Warnings.)  I believe you could get at least an idea of what happened based on the message that gets logged.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

Aug 6, 2010 at 9:38 AM

Thank you for your fast response :-)


Well, the thing I'm trying to configure up is a database trace listener. Can I have antother trace listener that listens for what happens to this one?

I think it is my text formatter that does something funny, by the way.

I took the standard WriteLog and made a copy of it called WriteLocalLog. The only difference is, that it has another parameter that I've added to the end of that function.

    @Message nvarchar(1500),
    @FormattedMessage ntext,
    @Miljoe nvarchar(100) = NULL,
    @LogId int OUTPUT


In my text formatter I have:

Thread Name: {threadName}{newline}
Win32 ThreadId:{win32ThreadId}{newline}
Extended Properties: {dictionary({key} - {value}{newline})}
Miljoe: {keyvalue(Miljoe)} {newline}

At first I didn't have the default NULL value for "Miljoe" in the sp, and things didn't work. I then added the default (as shown above), and it worked again.

Is there some need to register new keywords for either left or right side of the colon?

I noticed that the text Miljoe: and the keyvalue from the dictionary is now part of the formatted message column in the log table (which also comes from the Enterprise Lib 5 sample code).

So I think I'm ending up with this being a text formatter issue. I hope you can help. Thanks in advance :-)

Aug 6, 2010 at 9:46 AM

To confirm, you used WriteLocalLog as the write stored procedure of your database trace listener, is this correct?  If yes, then the problem was not because of the text formatter. As you noticed, the WriteLocalLog caused an error because the sp you used expect a value for the @Miljoe parameter but entlib's trace listener doesn't know about this so it doesn't add that parameter.  specifiying  @Miljoe nvarchar(100) = NULL value fixed the problem because you gave that parameter a default value.

If you need additional parameters to your stored procedure, you can't use the out-of-the-box database trace listener, you would need to create your own custom trace listener.  Adding it to the text formatter doesn't tell the database trace listener what other parameters to include when using the stored procedure. 

I hope this answers your question.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.