EL 5.0切换开启/关闭日志

时间:2012-06-11 08:16:02

标签: c# asp.net logging enterprise-library

我使用企业库5.0进行日志记录,我不知道如何关闭日志记录。目前,它已经开启并正常工作。

这是关于日志记录的web.config部分,它是使用EL 5.0 GUI自动创建的。

<loggingConfiguration name="" tracingEnabled="true" defaultCategory="Logging Only">
    <listeners>
      <add name="Flat File Trace Listener"
           type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..." 
           listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..." 
           fileName="WMSlog.log" formatter="Text Formatter" />
      <add enabled="false" name="Formatted EventLog TraceListener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..." 
           listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=..." 
           source="Exception Handling" 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=..." 
           template="Timestamp: {timestamp}{newline}&#xA;Message: {message}{newline}&#xA;Category: {category}{newline}&#xA;Machine: {localMachine}{newline}&#xA;App Domain: {localAppDomain}{newline}&#xA;ProcessId: {localProcessId}{newline}&#xA;Process Name: {localProcessName}{newline}&#xA;Thread Name: {threadName}{newline}&#xA;Win32 ThreadId:{win32ThreadId}{newline}" 
           name="Text Formatter" />
    </formatters>
    <categorySources>
      <add switchValue="Information" name="Logging Only">
        <listeners>
          <add name="Flat File Trace Listener" />
        </listeners>
      </add>
      <add switchValue="Error" name="Errors Only">
        <listeners>
          <add name="Formatted EventLog TraceListener" />
        </listeners>
      </add>
    </categorySources>
    <specialSources>
      <allEvents switchValue="All" name="All Events" />
      <notProcessed switchValue="All" name="Unprocessed Category" />
      <errors switchValue="Information" name="Logging Errors &amp; Warnings" />
    </specialSources>
  </loggingConfiguration>

我在上面的某些行中用...替换了我的数据。

目前我正在使用它来登录文件:

if (Logger.IsLoggingEnabled())
{
    Logger.Write("Some text...");
}

我需要能够使Logger.IsLoggingEnabled()返回false,我该怎么做?

1 个答案:

答案 0 :(得分:1)

只需使用Logging Enabled过滤器即可。请参阅http://msdn.microsoft.com/en-us/library/ff664548%28v=PandP.50%29.aspx