2

I have enabled tracing in a WCF service. Here is the system.diagnostics section:

<configuration>
  <system.diagnostics>
    <trace autoflush="true"/>
    <sources>
      <source name="System.ServiceModel" switchValue="All" propagateActivity="true">
        <listeners>
          <add name="xmlTraceListener" />
        </listeners>
      </source>
      <source name="System.ServiceModel.MessageLogging" switchValue="All">
        <listeners>
          <add name="xmlTraceListener" />              
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xmlTraceListener"
          type="System.Diagnostics.XmlWriterTraceListener"
          initializeData="C:\KryptonTracing\Traces.svclog" />
    </sharedListeners>
  </system.diagnostics>

Here is the system.serviceModel section showing diagnostics only:

<diagnostics wmiProviderEnabled="true">
  <messageLogging
       logEntireMessage="true"
       logMalformedMessages="true"
       logMessagesAtServiceLevel="true"
       logMessagesAtTransportLevel="true"
       maxMessagesToLog="3000"
   />
</diagnostics>

When I publish the service I see an Information event in the Windows Event Viewer on the server saying the following:

Message Logging has been turned on. Sensitive information may be logged in the clear, even if it was encrypted on the wire: for example, message bodies.

When I go to the C:\KryptonTracing folder on the server there is no Traces.svclog generated. I have gone into IIS and looked at the app pool identity this WCF service is running under and given that identity full control over the folder.. still nothing. No matter what I do I can't get anything to create a Traces.svclog. FYI, this service is wsHttpBinding (SSL) with custom authentication, but that should not matter.

I have tried everything in this post to no avail. Please help.

Community
  • 1
  • 1
BBauer42
  • 3,549
  • 10
  • 44
  • 81
  • why is your `` under ``? Is it a typo? It should be under root tag ``. – pepo Apr 23 '14 at 21:22
  • Sorry it was a typo, I've edited the post. – BBauer42 Apr 24 '14 at 12:29
  • And the WCF service is working correctly? Maybe a request never gets to the WCF to get logged. I don't see anything wrong with your configuration. – pepo Apr 24 '14 at 12:42
  • Yes the service is working. I can use the client to prove requests are going through and the DB is getting updated. I can also look at the IIS logs and see the service being hit. The service has wsHttpBinding and custom authentication but that shouldn't be an issue. – BBauer42 Apr 24 '14 at 13:17
  • When you set separate log files for System.ServiceModel.MessageLogging and System.ServiceModel does it work? Try to set permissions to everyone on C:\KryptonTracing folder. Just to be sure :) – pepo Apr 24 '14 at 13:46
  • No, when I separate them still no .svclogs are generated. I have added "everyone" to the folder with full permissions and still nothing. I have stopped and re-started IIS as well, still nothing. – BBauer42 Apr 24 '14 at 14:19

2 Answers2

4

I ended up using the WCF Configuration Editor to add the tracing to the web.config. It generated these two sections in my web.config.

<configuration>
  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelMessageLoggingListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Warning,ActivityTracing">
        <listeners>
          <add type="System.Diagnostics.DefaultTraceListener" name="Default">
            <filter type="" />
          </add>
          <add name="ServiceModelTraceListener">
            <filter type="" />
          </add>
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add initializeData="C:\Tracing\Krypton_Web_messages.svclog"
           type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           name="ServiceModelMessageLoggingListener" 
           traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
      <add initializeData="C:\Tracing\Krypton_Web_tracelog.svclog"
           type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
           name="ServiceModelTraceListener" 
           traceOutputOptions="Timestamp">
        <filter type="" />
      </add>
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>

...and this:

<diagnostics>
  <messageLogging logEntireMessage="true" logMalformedMessages="true"
    logMessagesAtTransportLevel="true" />
</diagnostics>

Then, before publishing I went and created the C:\Tracing folder and added "Everyone" with full permissions. Finally I published and now the two .svclog files are in the folder!!!! Not sure why my original configuration didn't work to begin with.

BBauer42
  • 3,549
  • 10
  • 44
  • 81
  • 2
    Thanks you helped me out, I was missing the 2nd part of the config. Just to others, this should be placed inside the tags – Maarten Kieft Mar 27 '17 at 09:15
1

Having the same problem I noticed that the app.config gui editor was writing switchValue="Advertencia,ActivityTracing" in spanish (the VS locale I use).

I changed it to switchValue="Warning,ActivityTracing" and it worked. Log files are now created.
Search online for 'TraceLevel Enumeration' to see available options.

Ivan Ferrer Villa
  • 2,129
  • 1
  • 26
  • 23