c# Circular traceListener not rolling files

885 views Asked by At

I'm using Microsoft.ServiceModel.Samples.CircularTracecListener binary to implement error logging on a webservice.

It should write to a file until maxFileSizeKB is reached and then roll to a secondary file. This process works fine when I test it with low file size limits and the rolling occurs in a short time.

The odd thing is when I set maxFileSizeKB, the next day I find that the logger overrited the main file and left the secondary untouched.

web.config file setting as follows:

  <system.diagnostics>
<sources>
  <source name="System.ServiceModel" switchValue="Information,ActivityTracing" >
    <listeners>
      <add name="CircularTraceListener" />
    </listeners>
  </source>
</sources>
<sharedListeners>
  <add name="CircularTraceListener" type="Microsoft.Samples.ServiceModel.CircularTraceListener,CircularTraceListener"
       initializeData="c:\log\webserviceLog.xml" maxFileSizeKB="5120" />
</sharedListeners>
<trace autoflush="true" />

Have someone encountered a similar issue?

I can only think of something rebooting the webservice and making it start with the first file.

Might it be the Application Pool Recycling?

When I check iis logs I see that the application pool is recicled around the same time my log file is being erased.

1

There are 1 answers

2
Rami A. On

The Microsoft.ServiceModel.Samples.CircularTraceListener code sample reads the maxFileSizeKB setting once. In order for changes to that setting to take affect, you must restart the hosting process.

Edit:

When you edit web.config, the IIS application pool will automatically get recycled by default.

If your IIS application pool is recycled, it will overwrite the main file (webserviceLog00.xml).

You can set "Application Pool > Advanced Settings... > Recycling > Disable Recycling for Configuration Changes" to true to prevent the application pool from restarting.