Dictionary<string,object> for Logging

Topics: Logging Application Block
Dec 5, 2008 at 10:33 PM
When writing a log entry (Logger.Write), we have the choice to pass in a Dictionary<string,object> as a parameter. So far, in the formatting template of a configuration file, I can only loop through the dictionary and display keys and/or values. Is there a way  that I can use the Key value to match a token in the template so that I display a Value of a certain key at a particular location. It will be so useful that I can any number of variables in the log entry and can still control their location/format.

Thanks!

Richard.
Dec 7, 2008 at 12:35 PM
Hi,

Are you asking if you can move the position of the extended property token?

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Dec 7, 2008 at 11:06 PM

Maybe the feature is alreay there but I don't know how to use.
Right now I can only format the extended properties (dictionary) this way:

{dictionary( Key: {key},  Value:{value})}

Is there a way I can reference the  value by key? for example:

First name: {dictionary{value["FirstName"]})}
Last name: {dictionary{value["LastName"]})}

 

Thanks!

Dec 8, 2008 at 9:14 AM
Hi,

Maybe this is what you're looking for. See this:
http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=7636

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com
Dec 9, 2008 at 7:49 PM
Valiant,
Thanks for the link. keyvalue token works great. I run into another problem though. I notice there is another token, property(). So I tried on an Exception object hoping it will give me access to the properties of the object. Somehow it doesn't return anything. Here is my test case:

I have a System.Exception object ex passed into the Logger.Write function like this,

Logger.Write(ex, "Debug", 100, 500, System.Diagnostics.TraceEventType.Information, "My Application", properties);

In the template, I use  {property(Source)}, {property(TargetSite)} and {property(StackTrack)} to access the properties of the Exception object but they return nothing.

What did I do wrong? Is property() token for this purpose?

Thanks!

Dec 10, 2008 at 4:47 AM

Hi,

Please see this thread. http://www.codeplex.com/entlib/Thread/View.aspx?ThreadId=16886

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com