2012-07-16 68 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