0

I am using enterprise library 5.0 for logging and I am not sure how to switch off the logging. Currently it is switched on and workng as it should.

Here is my web.config section on logging, it was created with automatically with the 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>

I have replaced my data with ... in some lines above.

At the moment I'm using this to log to a file:

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

I need to be able to make Logger.IsLoggingEnabled() return false, how do I do that?

1 Answer 1

1

Just use the Logging Enabled filter for this. See http://msdn.microsoft.com/en-us/library/ff664548%28v=PandP.50%29.aspx.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.