2012-12-21 39 views
1

我是EnterpriseLibrary.Logging的新手。在web.config中,loggingConfiguration下,我們有如下格式化:如何自定義loggingConfiguration的格式化程序?

<formatters> 
    <add name="Default Formatter" template="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {category}&#xA;&#xA;Priority: {priority}&#xA;&#xA;EventId: {eventid}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Title:{title}&#xA;&#xA;Machine: {machine}&#xA;&#xA;Application Domain: {appDomain}&#xA;&#xA;Process Id: {processId}&#xA;&#xA;Process Name: {processName}&#xA;&#xA;Win32 Thread Id: {win32ThreadId}&#xA;&#xA;Thread Name: {threadName}&#xA;&#xA;User Name: {userName}&#xA;&#xA; extended Properties: {dictionary({key} - {value}&#xA;)}" 
      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="&#xA;Timestamp: {timestamp(local)}&#xA;&#xA;Message: {message}&#xA;&#xA;Category: {category}&#xA;&#xA;Priority: {priority}&#xA;&#xA;EventId: {eventid}&#xA;&#xA;Severity: {severity}&#xA;&#xA;Title:{title}&#xA;&#xA;Machine: {machine}&#xA;&#xA;Extended Properties: {dictionary({key} - {value}&#xA;)}" 
      type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/> 
</formatters> 

在後面的代碼中,我們只設置消息到LogEntry。我想知道其他參數如何設置,例如時間戳,類別,優先級等。我添加了用戶名,但不起作用。任何人都可以點亮我嗎?

回答

3

以下是有關這些參數的Microsoft文章:Configuring Formatters。它討論了您可以在格式化程序中插入的各種令牌。

「用戶名」不是預定義的標記之一。但是你可以(可能)用LogEntry的ExtendedProperties屬性解決這個問題:

LogEntry le = new LogEntry(); 
le.ExtendedProperties.Add("username", "jsmith"); 
相關問題