2011-05-05 67 views
2

我是使用記錄器的新手。哪裏企業庫4.1記錄器,日誌?

我已經使用配置嚮導完成了它的配置,但我無法理解它在哪裏記錄消息。我什至看到app.config文件,但無法找到任何日誌記錄源。

請指導我在哪裏做日誌,以及如何檢查日誌。

這裏是我的配置文件:

<?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" /> 
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" /> 
    </configSections> 
    <loggingConfiguration name="Logging Application Block" tracingEnabled="true" 
    defaultCategory="General" logWarningsWhenNoCategoriesMatch="true"> 
    <listeners> 
     <add fileName="C:\Users\Administrator\Desktop\EAMS\trace.log" 
     header="----------------------------------------" footer="----------------------------------------" 
     formatter="" listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     traceOutputOptions="LogicalOperationStack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     name="FlatFile TraceListener" /> 
     <add source="Enterprise Library Logging" 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="LogicalOperationStack" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
     name="Formatted EventLog 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;Extended Properties: {dictionary({key} - {value}&#xD;&#xA;)}" 
     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="General"> 
     <listeners> 
      <add name="Formatted EventLog TraceListener" /> 
     </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="Formatted EventLog TraceListener" /> 
     </listeners> 
     </errors> 
    </specialSources> 
    </loggingConfiguration> 
    <connectionStrings> 
    <add name="ConnectionString" connectionString="Data Source=YAWARLAPTOP;Initial Catalog=EAMS;Integrated Security=true" 
     providerName="System.Data.SqlClient" /> 
    </connectionStrings> 
</configuration> 

感謝

回答

2

您需要配置一個或多個Trace Listeners。另請參閱Configuration Overview

編輯1 感謝您的配置文件示例。您正在將消息記錄到應用程序事件日誌中。正常情況下,請打開Event Log,您將能夠在該處看到您的消息。

編輯2 在您原來的問題,你問了消息記錄在哪裏。這個答案已經提供給你。當你寫一個問題時,最好先指定,你試圖達到什麼目的。要登錄到平面文件,在配置了平面文件偵聽器之後,您需要將此偵聽器的引用添加到源代碼中。在你的例子中看看它是如何處理事件日誌跟蹤監聽器的,並遵循相同的模式。

+0

我添加了TraceListener(平面文件)並做了配置,但它仍然沒有寫入文件。你可以檢查我的配置文件,並建議。 – user576510 2011-05-05 12:12:08

+1

更新了我的答案。 – 2011-05-05 12:50:30

+0

謝謝@zespri,但我想在純文本文件中記錄錯誤。請諮詢。 – user576510 2011-05-05 13:04:14

1

這是正確的。 身份驗證已添加到v5.0中的電子郵件tracelistener。

如果您必須使用v4.1,那麼在EntLibContrib上有一個電子郵件tracelistener的版本,其身份驗證。

相關問題