2009-08-26 2 views
0

우리가 사용하는 마이크로 소프트의 Enterprise Library (4.1) 자주 다음과 같은 문제가 있습니다 엔터프라이즈 라이브러리 ExceptionManager : "로그 항목 문자열이 너무 깁니다."

[ArgumentException: Log entry string is too long. A string written to the event log cannot exceed 32766 characters.] 
    System.Diagnostics.EventLog.InternalWriteEvent(UInt32 eventID, UInt16 category, EventLogEntryType type, String[] strings, Byte[] rawData, String currentMachineName) +1005489 
    System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +264 
    System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData) +87 
    System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type) +14 
    Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher.WriteToLog(String entry, EventLogEntryType type) in D:\temp\Exception Management\Code\CS\Microsoft.ApplicationBlocks.ExceptionManagement\ExceptionManager.cs:647 
    Microsoft.ApplicationBlocks.ExceptionManagement.DefaultPublisher.Publish(Exception exception, NameValueCollection additionalInfo, NameValueCollection configSettings) in D:\temp\Exception Management\Code\CS\Microsoft.ApplicationBlocks.ExceptionManagement\ExceptionManager.cs:634 
    Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.PublishToDefaultPublisher(Exception exception, NameValueCollection additionalInfo) in D:\temp\Exception Management\Code\CS\Microsoft.ApplicationBlocks.ExceptionManagement\ExceptionManager.cs:287 
    Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(Exception exception, NameValueCollection additionalInfo) in D:\temp\Exception Management\Code\CS\Microsoft.ApplicationBlocks.ExceptionManagement\ExceptionManager.cs:232 
    Microsoft.ApplicationBlocks.ExceptionManagement.ExceptionManager.Publish(Exception exception) in D:\temp\Exception Management\Code\CS\Microsoft.ApplicationBlocks.ExceptionManagement\ExceptionManager.cs:66 
... 

는 불행하게도 DefaultPublisherWriteToLog 방법은 어떤 경계가 그래서 우리의 원래 스택 트레이스가 손실 이벤트 로그에 기록하기 전에 확인하지 않습니다합니다.

이 문제를 해결할 수있는 방법이 있습니까 (구성 설정이 바람직 함). DefaultPublisher을 계속 사용합니까?

답변

1

메시지가 너무 길어서 EventLog에 로그온 할 수 없으므로 (이미 알았습니다!). 나는 당신의 세 가지 옵션이 생각 : (예를 들어 플랫 파일) 이벤트 로그에

  • 로그 메시지 실용적인 크기 제한이 있지만 발생하는 오류를 리디렉션하지 않는 기록의 모든 대상에 쓸

    1. 변경 엔터프라이즈 라이브러리와 실용적인 크기 제한이없는 대상 (예를 들어 플랫 파일)
    2. 는 "문제를"해결에

    옵션 1과 2는 구성을 통해 수행 할 수 있습니다. 옵션 2를 지원하려면 LoggingConfiguration 섹션에서 오류 대상을 구성해야합니다. 그것은 다음과 유사합니다

    <specialSources> 
        <errors name="errors" switchValue="All"> 
        <listeners> 
         <add name="Flat File Destination"/> 
        </listeners> 
        </errors> 
    </specialSources> 
    <listeners> 
        <add name="Flat File Destination" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging" fileName ="loggerErrors.log" /> 
    </listeners> 
    



    내 환경 설정 옵션이 몇 가지 악재가 있기 때문에 옵션 1로 이동하는 것입니다. 옵션 2의 네거티브 중 일부는 다음과 같습니다.

    • 성공적인 로그 쓰기는 모두 EventLog로 보내지고 발생하는 모든 오류 (너무 긴 예외 포함)는 파일에 기록됩니다. 이제 로그가 두 개의 개별 데이터 소스로 확장되므로 이로 인해 문제가 발생합니다.
    • 오류 로그는 성공적인 로그 메시지와 다른 형식으로되어있어 로그를 구문 분석하기가 어려울 수 있습니다.
    • 다른 예외가 발생, 포착 및 처리되기 때문에 너무 긴 문자열을 기록하려고하면 성능이 저하됩니다.
  • 관련 문제