Logging Template Editor overview?

Topics: Logging Application Block
Apr 13, 2007 at 1:34 PM
I'm a relative newbie here in the Enterprise Library world. I'm hoping someone can point me to a link that clearly describes how some of the predefined Tokens relate to the code. I'm particularly interested in the dictionary (key and value) implementation. What dictionary is this token referring to.

I'm using the PIAB and I've defined a Logging Handler for it. I was hoping it would print out the name of the method it was being was being invoked for, but that doesn't seem to be the case. Is there a listing of what each of the more obscure Tokens refers to. I've mentioned "dictionary" already, what about "title" and "property()".

Thanks in advance,
Apr 13, 2007 at 5:27 PM
Hi Justin -

In general, you can use {foo} to access a "standard" property in LogEntry, and (in the 3.0 block) {property(foo)} to access any property (including non-standard ones in derived classes) via reflection. So {title} will return the value from the standard LogEntry.Title property. The PIAB uses a derived class called TraceLogEntry that includes properties such as MethodName, ReturnValue, CallStack and Exception. Since these propertes aren't part of LogEntry, you need to use the property token, for example {property(MethodName)}

The dictionary token is used to retrieve values out of the LogEntry.ExtendedProperties dictionary. The default text formatter template shows how to use this token to enumerate through all of the proerties in the dictionary, eg: {dictionary({key} - {value})}

May 25, 2007 at 1:35 AM
Edited May 25, 2007 at 1:39 AM
For the ExtendedProperties dictionary, in addition to iterating through all properties with the {dictionary({key} - {value})} syntax, you can pull out an individual property using {keyvalue(extendedPropertyKey)}, where extendedPropertyKey is the item's key. Example:

    LogEntry le = new LogEntry("Verbose Message", "General",
        1, 1, TraceEventType.Verbose, "Verbose Message Title", null);
    le.ExtendedProperties.Add("Alias", "johns");
    le.ExtendedProperties.Add("Email", "John.Smith@microsoft.com");
TextFormatter's "FormatString" property:
Timestamp: {timestamp}, Email: {keyvalue(Email)}, Alias: {keyvalue(Alias)}

Timestamp: 5/25/2007 12:54:09 AM, Email: John.Smith@microsoft.com, Alias: johns