我是EnterpriseLibrary.Logging的新手。在web.config中,在loggingConfiguration下,我们有以下格式化程序:
<formatters>
<add name="Default Formatter" template="
Timestamp: {timestamp(local)}

Message: {message}

Category: {category}

Priority: {priority}

EventId: {eventid}

Severity: {severity}

Title:{title}

Machine: {machine}

Application Domain: {appDomain}

Process Id: {processId}

Process Name: {processName}

Win32 Thread Id: {win32ThreadId}

Thread Name: {threadName}

User Name: {userName}

 extended Properties: {dictionary({key} - {value}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
<add name="DBA Formatter" template="
Timestamp: {timestamp(local)}

Message: {message}

Category: {category}

Priority: {priority}

EventId: {eventid}

Severity: {severity}

Title:{title}

Machine: {machine}

Extended Properties: {dictionary({key} - {value}
)}"
type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</formatters>
在后面的代码中,我们只将消息设置为LogEntry。我想知道其他参数是如何设置的,例如时间戳,类别,优先级等。我添加了用户名,但不起作用。任何人都可以对我有所了解吗?
答案 0 :(得分:3)
以下是有关这些参数的Microsoft文章:Configuring Formatters。它讨论了可以在格式化程序中插入的各种标记。
“用户名”不是预定义标记之一。但是你可以(可能)使用LogEntry的ExtendedProperties属性来解决这个问题:
LogEntry le = new LogEntry();
le.ExtendedProperties.Add("username", "jsmith");