2012-12-21 3 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"); 
관련 문제