2012-05-04 45 views
2

我正在使用EntLib 4.1。我想將日誌條目與不同的類別關聯起來。我的類別將反映各種有趣的信息,比如上下文的種類(比如「批量」或「在線」)和功能區域(比如「發票」或「訂單」)。EntLib登錄到類別

我已經完成了日誌記錄代碼,但我認爲我在配置中做錯了事。我試圖實現的是將所有條目記錄到類別「批處理」中,最終記錄在名爲「批處理」的事件日誌中,以及應用程序日誌中的所有其他內容。 (我已手動此名稱創建一個自定義事件日誌。)

然而,記錄與類別批項目,而不是得到記錄到應用程序日誌,每個條目包含以下序言:

 
Message: Tracing to LogSource 'Batch' failed. Processing for other sources will continue. See summary information below for more information. Should this problem persist, stop the service and check the configuration file(s) for possible error(s) in the configuration of the categories and sinks. 

EntLib配置文件:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <configSections> 
     <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </configSections> 
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true" 
     defaultCategory="APPLICATION" logWarningsWhenNoCategoriesMatch="true"> 
     <listeners> 
      <add source="Project II Logger" formatter="Text Formatter" log="Batch" 
       machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="BatchListener" /> 
      <add source="Project II Logger" formatter="Text Formatter" log="Application" 
       machineName="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="DefaultListener" /> 
      <add fileName="c:\temp\trace.log" header="----------------------------------------" 
       footer="----------------------------------------" formatter="ExceptionFormatter" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       traceOutputOptions="Callstack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="Exception TraceListener" /> 
     </listeners> 
     <formatters> 
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;ErrorMessages: {errorMessages}" 
       type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="ExceptionFormatter" /> 
      <add template="Timestamp: {timestamp}&#xD;&#xA;Message: {message}&#xD;&#xA;Category: {category}&#xD;&#xA;Priority: {priority}&#xD;&#xA;EventId: {eventid}&#xD;&#xA;Severity: {severity}&#xD;&#xA;Title:{title}&#xD;&#xA;Machine: {machine}&#xD;&#xA;Application Domain: {appDomain}&#xD;&#xA;Process Id: {processId}&#xD;&#xA;Process Name: {processName}&#xD;&#xA;Win32 Thread Id: {win32ThreadId}&#xD;&#xA;Thread Name: {threadName}&#xD;&#xA;ErrorMessages: {errorMessages}" 
       type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       name="Text Formatter" /> 
     </formatters> 
     <categorySources> 
      <add switchValue="All" name="APPLICATION"> 
       <listeners> 
        <add name="DefaultListener" /> 
       </listeners> 
      </add> 
      <add switchValue="All" name="Batch"> 
       <listeners> 
        <add name="BatchListener" /> 
       </listeners> 
      </add> 
     </categorySources> 
     <specialSources> 
      <allEvents switchValue="All" name="All Events" /> 
      <notProcessed switchValue="All" name="Unprocessed Category" /> 
      <errors switchValue="All" name="Logging Errors &amp; Warnings"> 
       <listeners> 
        <add name="DefaultListener" /> 
       </listeners> 
      </errors> 
     </specialSources> 
    </loggingConfiguration> 
</configuration> 
+0

你看到在應用程序日誌中的消息表明登錄到批處理類別失敗。它是否給你任何其他信息,如堆棧跟蹤? –

+0

是的,我得到了一個堆棧跟蹤。但是有(也沒有理由)認爲我記錄的背景與這件事有任何關係,所以我沒有發佈。 –

回答

0

我的猜測是,您沒有在該日誌中創建適當的事件日誌和/或事件源。

該問題似乎沒有出現在配置文件中。

如果您選擇從bat文件或控制檯應用程序設置新日誌等,請確保在管理員下運行它。

creating log and source win 7

+0

你的回答是錯誤的,但我會接受它。 EntLib在第一次將某些東西記錄到類別中時爲您創建日誌和源,因此您無需這樣做。但問題是相關的:我嘗試使用相同的源登錄到兩個不同的位置。這在Windows事件日誌模型中證明是非法的,所以只有非描述性的錯誤信息可以歸咎於EntLib。 (我希望源代碼反映源代碼,並將其活動摘要信息記錄到集中日誌中,但在其他地方記錄更詳細的跟蹤信息)不允許! –

+0

「企業庫日誌記錄」源自動註冊,但沒有其他自定義來源。 – Legends