Accessing individual Extended properties

Topics: Logging Application Block
Feb 27, 2007 at 5:37 AM
Hi,
I am setting some custom properties using the extendedproperties property of the LogEntry class. Is there any way to access the individual properties in the TextFormatter Template?
For example,

I am setting the properties thus :

LogEntry ent = new LogEntry();
ent.Message = Message;
ent.Priority = (int) LogLevel;
ent.ExtendedProperties.Add("MyPropOne", "PropOneString");
ent.ExtendedProperties.Add("MyPropOne", "PropTwoString");


in the text formatter, I would like to do something like :
txtFormatter = new Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter("< Timestamp : {timestamp} > " +
"< PropertyOne : {dictionary({MyPropOne})} >< PropertyTwo : {dictionary({MyPropTwo})}>{newline}" +
"{message}"
);

If I use {dictionary({value})}, I can get all the values in the extended properties {dictionary({key})} gives me the keys. I tried various permutations I can think of to access the individual entries in the extended properties dictionary, but haven't had any luck.

Also, can someone point me to a definitive list of all the "standard" properties that I can use in the text properties I know there is {timestamp} {threadid} and a few others I can see in the example config file, but is there documentation somewhere that lists all these properties?

Any help would be much appreciated.
Thanks.

Feb 27, 2007 at 3:49 PM
We haven't touched this code for a very long time, so I could be off base here - but maybe {keyvalue()} does what you want?

Tom
Feb 27, 2007 at 4:42 PM
It is {keyvalue()}.

The best way to find a list of all tokens that can be placed in the template of a Formatter is to use the GUI Configuration Editor.

If you select the Formatter you use to format your log messages, you can choose the Template Editor in the property grid to define a template for the format. In the Template Editor is a dropdown menu that contains a list of all tokens that can be used within the template.

One of the tokens mentioned is the {keyvalue()} token as mentioned above.

Regards,

Dave

_______________________

David Hayden
Microsoft MVP C#
Feb 27, 2007 at 4:56 PM
Here is some example code that I wrote in my application:

IDictionary<string, object> properties = new Dictionary<string, object>();
properties.Add("MyKey", "MyValue");
Logger.Write("Hello", properties);

In the Template Editor of my Text Formatter I added this:

MyKey: {keyvalue(MyKey)}

which displayed this in the EventLog:

MyKey: MyValue

Regards,

Dave

______________________

David Hayden
Microsoft MVP C#

Feb 27, 2007 at 11:46 PM
Cool. Thanks guys. Thats exactly what I was looking for. Only recently discovered Enterprise Library and loving it to bits. Can't wait for v3.
Dec 11, 2007 at 8:01 PM
I am using key names that have a '.' in them such as 'Data.Property' and they don't seem to be picked up by the keyvalue function. Is this a bug or expected behavior?
Dec 11, 2007 at 8:10 PM


lfoust wrote:
I am using key names that have a '.' in them such as 'Data.Property' and they don't seem to be picked up by the keyvalue function. Is this a bug or expected behavior?


Nevermind. It was my bug. Disregard my previous entry. Next time I'll debug more thuroughly.