EntLib 5.0 Logging Formatter does not format Extended Properties

Topics: Logging Application Block
Mar 9, 2011 at 7:20 PM

Hi Folks,

Am I the only one to notice that extended properties are not formatting correctly? If one uses the Default formatting template, you can see the extended properties buried in the {message} token, but if you examine the Extended Properties: {dictionary({key} - {value}{newline})} at the very end of the formatted message, you'll see it's always blank. Am I doing something wrong or is this just an annoying bug? I've also tried using {keyvalue(mykey)} to no avail.

What gives?

Thanks

Mar 10, 2011 at 1:00 AM

I'm not getting this behavior.  Could you send a small repro?

 

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

Mar 10, 2011 at 3:35 PM

Upon making the repro, I discovered my problem! I was inadvertantly using an overload of the Logger.Write method which permits passing a complete logEntry, while forming a new logEntry:

            var logEntry = new LogEntry {Message = message};
            logEntry.ExtendedProperties.Add("Logging Adapter", "IExtendedLogger");
            logEntry.Categories = categories;
            Logger.Write(logEntry, categories, 3, 2, TraceEventType.Information, "The title");

Thus, what was happening is that I was nesting log entries, so the extended properties of the logEntry above did not show on the outer log entry created by the overload (where I was omitting extended properties). Not obvious. A powerfull feature, but confusing to a novice. I changed my code to:

            var categories = new List<String> {"Info"};
            var logEntry = new LogEntry {Message = "Log Entry Test Message"};
            logEntry.ExtendedProperties.Add("Logging Adapter", "IExtendedLogger");
            logEntry.Categories = categories;
            logEntry.ExtendedProperties.Add("A","The Value");

            Logger.Write(logEntry);

Much better... :-)

One more thing though. If you try to set up logging to a db and try to alter the default LocalSqlServer entry via the config tool, it will NOT write your settings to the config file, they're ALWAYS lost. You have to create an entirely new entry from scratch for it to write the config file. If you Delete the LocalSqlServer entry, it will reappear, but you still cannot persist any alterations to it via the config tool. Is there a reason for this?

Thanks so much for your interest.

-john

Mar 11, 2011 at 12:11 AM
Edited Mar 11, 2011 at 12:11 AM

The LocalSqlServer connection string is an entry from the machine.config file.  You cannot edit or delete it using the configuration tool so you shouldn't touch it. 

 

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

Mar 11, 2011 at 12:28 AM

Aha, I see.

Thank you for this explanation.

-John

From: AvanadeSupport [email removed]
Sent: March-10-11 7:11 PM
To: Morissette, John
Subject: Re: EntLib 5.0 Logging Formatter does not format Extended Properties [entlib:249076]

From: AvanadeSupport

The LocalSqlServer connection string is an entry from the machine.config file. You cannot edit or delete it so you shouldn't touch it.

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