C# – WCF logging, set max file size

cdiagnosticsloggingwcf

Im using Microsoft Service Configuration Editor to setup diagnostics(WCF logging) and I can´t find any way to set the max file size?

I have found the MaxSizeOfMessageToLog but that do nothing about the file size?

Edit 1: According to this : http://msdn.microsoft.com/en-us/library/aa395205.aspx
There should be a maxFileSizeKB at the sharedListeners level but when hitting space in the add tag I do not get the possibility to type maxFileSizeKB?

Edit 2: When adding the maxFileSizeKB the serivce will not start anymore, instead I will get the following excetion :

'maxFileSizeKB' is not a valid configuration attribute for type 'System.Diagnostics.XmlWriterTraceListener'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Configuration.ConfigurationErrorsException: 'maxFileSizeKB' is not a valid configuration attribute for type 'System.Diagnostics.XmlWriterTraceListener'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Edit 3 :

I had to download the Circular TraceListener sample and include it in my project, there is no built in fileSize limiter.

My config looks like this now :

<system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning, ActivityTracing">
        <listeners>
          <add name="ServiceModelMessageLoggingListener"/>
        </listeners>
      </source>
      <source name="System.ServiceModel" switchValue="Warning,ActivityTracing"
        propagateActivity="false">
        <listeners>
          <add name="ServiceModelTraceListener"/>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\My\MyRelease 0.31\Host\My.Host.Dev\web_messages.svclog"
        type="Microsoft.Samples.ServiceModel.CircularTraceListener,CircularTraceListener"
        name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp" maxFileSizeKB="1024">
        <filter type="" />
      </add>
      <add initializeData="C:\My\MyRelease 0.31\Host\My.Host.Dev\web_tracelog.svclog"
        type="Microsoft.Samples.ServiceModel.CircularTraceListener,CircularTraceListener"
        name="ServiceModelTraceListener" traceOutputOptions="Timestamp" maxFileSizeKB="1024">
        <filter type="" />
      </add>
    </sharedListeners>

This is limiting the message log file but not the trace log file?

Best Answer

It's because the link your gave use a custom trace listener ("Microsoft.ServiceModel.Samples.CircularTraceListener"), which have a "maxFileSizeKB" property.

There is no built-in functionnality to limit/roll svclog files, so you really need to use a custom trace listener. You can use the sample used in your link (read at the end of the article how to download the code). Or here is another one that can be usefull.