2011-03-04 18 views
2

這裏是我的配置文件爲什麼它從格式化不是下面的模板

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <configSections> 
     <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" /> 
    </configSections> 
    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General" > 
    <listeners> 
     <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       source="Enterprise Library Logging" formatter="Text Formatter" 
       log="" machineName="." traceOutputOptions="None" /> 
     <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       fileName="F:\MyLogFile.log" footer="" header="" rollInterval="Hour" 
       traceOutputOptions="None" formatter="Text Formatter" /> 
    </listeners> 
    <formatters> 
     <add type="Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.TextFormatter, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" 
       template="{timestamp} {severity} {message} " 
       name="Text Formatter" /> 
    </formatters> 
    <categorySources> 
     <add switchValue="All" name="General"> 
     <listeners> 
      <add name="Rolling Flat File Trace Listener" /> 
     </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="Rolling Flat File Trace Listener" /> 
     </listeners> 
     </errors> 
    </specialSources> 
    </loggingConfiguration> 
</configuration> 

,當我使用我得到在日誌文件中按以下

Logger.Write("hello world", "", 0, 0, TraceEventType.Information); 

代碼

3/4/2011 7:40:26 PM錯誤類別''沒有明確的映射。日誌條目:
時間戳:2011/3/4下午七時40分26秒
消息:你好世界
類別:
優先級:0
事件ID:0
嚴重性:信息
標題:
機:MYPC
應用程序域:ConsoleApplication1.vshost.exe
的ProcessID:8912
進程名稱:C:\ ConsoleApplication \ BIN \調試\ ConsoleApplication.vshost.exe
主題名稱:
的Win32的ThreadId:5496
擴展屬性:

我是什麼做錯了,使人們不尊重模板=「{時間戳} {嚴重} {消息}」我在定義格式化。

+0

你使用什麼記錄器?並顯示所有配置文件 – Serghei 2011-03-04 19:48:19

+0

Enterpriese庫日誌塊。你在配置文件中看到了什麼? – 2011-03-04 20:00:04

回答

2

您已經使用名稱「常規」定義了您的類別,但是在您登錄時您使用的是類別「」。

Logger.Write("hello world", "", 0, 0, TraceEventType.Information); 

所以你的LogEntry沒有被你的「常規」類別,而是由specialSourcenotProcessed處理。這就是信息「沒有明確的類別映射」正試圖告訴你。

要使用類別中的Write方法傳遞名稱:

Logger.Write("hello world", "General", 0, 0, TraceEventType.Information); 

或因爲「大將軍」被定義爲defaultCategory不指定類別。

+0

謝謝,不過現在我得到了「嘗試獲取LogWriter類型的實例時出現激活錯誤,鍵」「」錯誤。不確定這是否可以通過在dll中配置企業庫日誌記錄塊來實現。儘管我已經發布了一個單獨的問題。 – 2011-03-07 14:28:40

相關問題