Thursday, October 21, 2010

Enterprise Library–Logging Formatter Token List

Here is the list of tokens available for the text formatter under the logging block:

activity id {activity}
appDomain Name {appDomain}
category {category}
errorMessages {errorMessages}
event Id {eventid}
machine Name {machine}
message {message}
priority {priority}
processId {processId}
processName {processName}
severity {severity}
thread Name {threadName}
timeStamp {timestamp} or {timestamp(local)}
titleToken {title}
win32 ThreadId {win32ThreadId}

Dictionary {dictionary({key} – {value})}

Formatting tokens:
Tab {tab}
NewLine {newline}

Here is a sample template for the text formatter:

"Timestamp: {timestamp(local)}{newline}
{tab}Message: {message}{newline}
{tab}Category: {category}{newline}
{tab}Priority: {priority}{newline}
{tab}EventId: {eventid}{newline}
{tab}Severity: {severity}{newline}
{tab}Title:{title}{newline}
{tab}Machine: {machine}{newline}
{tab}Application Domain: {appDomain}{newline}
{tab}Process Id: {processId}{newline}
{tab}Process Name: {processName}{newline}
{tab}Win32 Thread Id: {win32ThreadId}{newline}
{tab}Thread Name: {threadName}{newline}
{newline}
{tab}Extended Properties: {dictionary({key} - {value})}"

And here is a template formatted for output to XML: (my preferred method for logging to the database)

 template="<log><timestamp>{timestamp(local)}</timestamp>
                    <message>{message}</message>
                    <category>{category}</category>
                    <priority>{priority}</priority>
                    <eventId>{eventid}</eventId>
                    <severity>{severity}</severity>
                    <title>{title}</title>
                    <machine>{machine}</machine>
                    <applicationDomain>{appDomain}</applicationDomain>
                    <processId>{processId}</processId>
                    <processName>{processName}</processName>
                    <win32ThreadId>{win32ThreadId}</win32ThreadId>
                    <threadName>{threadName}</threadName>
                    <extendedProperties>
                     {dictionary(<key>{key}</key><value>{value}</value>)}</extendedProperties></log>"
The < and > are there so that you can insert it in the config file without VS complaining about invalid xml characters.

No comments:

Post a Comment

Remember, if you want me to respond to your comment, then you need to use a Google/OpenID account to leave the comment.