Database trace listener replaces log message line ending characters with spaces

Topics: Logging Application Block
Jan 13, 2009 at 5:13 PM
The Database trace listener replaces line ending characters (0D 0A) in the log message with spaces which makes the message difficult to read.  This happens for both the "Message" column as well as the "FormattedMessage" column.  Is this be design or is this a bug?  Can this behavior be changed/fixed?

BTW other trace listeners (flat file, email, etc.) do not do this.  The same message with these listeners will retain the correct lines endings.  All of the trace listeners are using the same formatter (Logging.Formatters.TextFormatter).

Thanks,
David
Jan 14, 2009 at 4:13 AM
Hi,

Are you refering to the actual message that is already logged to the database? I tried Logging something thru a Database trace listener, and check the output log in the database, i checked the Message and FormattedMessage column of the "dbo.Log" table and there is no extra spaces in the logged string. Can you give me the steps so that i can confirm it and have that logged.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 15, 2009 at 5:35 PM
Hi Valiant,

To see this problem, your log message needs to contain line ending characters (0D 0A).  Try logging any Exception log message (use TextExceptionFormatter option) with both a flat file trace listener and a DB trace listener configured.

Then compare the Stack Trace portion of the message between the flat file and the database.
In the flat file, the stack trace will be on multiple lines due to the line ending characters (0D 0A).
In the DB, the stack trace will all be on a single line due to the line ending characters having been replaced with two spaces.

Thanks,
David
Jan 16, 2009 at 5:43 AM
Hi David,

I think it would be just normal to behave that way. I tried your steps, but maybe its just the way that the DB translates the (0D 0A). I also tried copying the content of Message column and paste it to a notepad, i tried comparing it so the result of the flatfile and it looks just the same.


Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Jan 23, 2009 at 12:36 AM
Edited Jan 23, 2009 at 12:44 AM
Oops, it turns out the line ending characters are being inserted into the database after all.  The problem was that I was querying the log records from SQL Server Management Studio with the "Results to Grid" option selected and I guess Grid replaces the line ending characters in the results with spaces.  Once I changed this option to "Results to Text", the line endings show up fine.

Thanks,
David