0

我正在使用企业库 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,我该怎么做?

4

1 回答 1

1

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

于 2012-06-11T16:49:20.427 回答