2012-07-16 62 views
1

我使用記錄5.0,當我打電話:登錄由Microsoft.Practices.EnterpriseLibrary.Logging 5.0不起作用

LoggerUtils.WriteLog("test","test"); 

它通過但我沒有日誌信息。

下面是我的配置(在的config.web):

 <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /> 

    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" /> 

     <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 **fileName="Log\test.log"** 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" footer="{" formatter="Text Formatter" header="}" rollFileExistsBehavior="Increment" rollSizeKB="2048" traceOutputOptions="None" /> 
    </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: {timestamp} | Message: {message} | Category: {category} | Machine: {localMachine}" name="Text Formatter" /> 
    </formatters> 
    <categorySources> 
     <add switchValue="All" name="General"> 
     <listeners> 
      <add name="Event Log 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="Event Log Listener" /> 
     </listeners> 
     </errors> 
    </specialSources> 
    </loggingConfiguration> 

我已配置的文件名= 「登錄\ test.log中」,但我在它沒有數據。

請幫我找出爲什麼日誌不起作用。

+1

喜升。請考慮標記Gerrie的答案是正確的,因爲您的評論表明這是正確的答案。 – SeanKilleen 2012-12-10 14:18:02

回答

2

你沒有文件監聽器的配置添加到偵聽器列表:

<categorySources> 
    <add switchValue="All" name="General"> 
    <listeners> 
     <add name="Rolling Flat File Trace Listener" /> 
    </listeners> 
    </add> 
</categorySources> 
+0

是的,非常感謝。你節省了我的時間。 – 2012-07-17 06:54:17