12

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?

toad
  • 1,351
  • 8
  • 14
Banshee
  • 15,376
  • 38
  • 128
  • 219
  • could you please include your config-section? –  Apr 11 '12 at 07:26
  • btw - here's the code for `CircularTraceListener`: https://cbasetest.svn.codeplex.com/svn/SoftLibrary_Dev/SDFL/Reputation/RepuService/FrontEndCommon/CircularTraceListener.cs –  Apr 11 '12 at 07:28
  • btw, have you ever tried to utilize "Microsoft Service Configuration Editor" for this task ("C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\SvcConfigEditor.exe") –  Apr 11 '12 at 07:32
  • `maxFileSizeKB` is a custom attribute on the `CircularTraceListener` class which is the subject of that SDK sample. – anton.burger Apr 11 '12 at 08:12
  • You are of course right. I hade to download the Circular TraceListener and include that DLL into my project. I have now set it up but the trace file is still growing while the message stays in the right size? Se Edit 3. – Banshee Apr 11 '12 at 08:24
  • @SnowJim - (not sure if this resolved, but) Set the `propagateActivity="true"` in your `ServiceModelTraceListener` Source – VoodooChild Aug 28 '12 at 17:46
  • @Banshee, How did you solve the problem of the growing trace file? – Itay.B Feb 27 '17 at 06:59

2 Answers2

12

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.

Fabske
  • 2,106
  • 18
  • 33
  • The samples are gone from the Microsoft site now, but code can be found here: [github.com/SebastiaanLubbers/WF_WCF_Samples](https://github.com/SebastiaanLubbers/WF_WCF_Samples/tree/master/WCF/Basic/Management/CircularTracing) – Richard Sinden May 21 '21 at 09:10
8

Just want to add to @Fabske answer that inorder for this to work

1) Download WCF samples: http://go.microsoft.com/fwlink/?LinkId=150780

2) Open :\WF_WCF_Samples\WCF\Basic\Management\CircularTracing

3) Build the solution and grab the CircularTraceListener.dll

4) Add that dll to your project references

5) Update your configuration as shown http://msdn.microsoft.com/en-us/library/aa395205(v=vs.100).aspx

VoodooChild
  • 9,776
  • 8
  • 66
  • 99
  • 2
    Also note the namespace typo in the MSDN article (as pointed out by a commentator), lest you waste a bunch of time like I did trying to figure out why your project won't run... – Shelly Skeens Oct 31 '13 at 16:38
  • I did that. Downloaded sample, built .dll, put it into my project's references, did that configuration thing and cared for the typo (which is not present any more). But ``mxFileSizeKB`` is still marked as unknown and I don't get a file. – ecth Apr 15 '15 at 07:45
  • 1
    Okay. Managed it. My Code: http://pastebin.com/JeYE3rEt. ``maxFilesizeKB`` is still marked as unknown but it works and the file stays with the right size. Also my switchValue is ``All`` and you might want to set it to ``Information``, ``Warning`` or something like that ;) – ecth Apr 15 '15 at 08:32
  • I wasn't getting a file created until I changed the switchValue to **All**. Also if you get an [ConfigurationErrorsException CircularTraceListener error try this](http://stackoverflow.com/a/37961908/495455) – Jeremy Thompson Jul 18 '16 at 06:50