Search code examples
wcfsystem.diagnostics

System.Diagnostics ServiceModel message logging not working for integration test project


I have an integration test project, that I run tests on my classes that consume an external WCF service

In MyApp.IntegrationTests I have an app.config file that looks like:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>

  </connectionStrings>
  <appSettings>

  </appSettings>
  <system.serviceModel>
    <bindings>
      -- ommitted for brevity
    </bindings>
    <client>
      <endpoint name="IWhatever"
                address="https://url.com/Whatever.svc"
                binding="basicHttpBinding"
                bindingConfiguration="basicHttpsBindingConfiguration"
                contract="IWhatever" />

    </client>
  </system.serviceModel>

  <system.diagnostics>
    <sources>
      <source name="System.ServiceModel.MessageLogging">
        <listeners>
          <add initializeData="soap-log.xml" type="System.Diagnostics.XmlWriterTraceListener"
            name="messages" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
</configuration>

As you can see, I'm trying to log my calls to soap-log.xml

If I run my tests, no log file is created.

What is confusing me is, if I have the system.diagnostics block in my actual web app project, the xml log file is created.


Solution

  • It's seems you missed messageLogging element. MSDN link.

    <system.serviceModel>
      <diagnostics>
        <messageLogging 
             logEntireMessage="true" 
             logMalformedMessages="true"
             logMessagesAtServiceLevel="true" 
             logMessagesAtTransportLevel="false"
             maxMessagesToLog="3000"
             maxSizeOfMessageToLog="20000"/>
      </diagnostics>
    </system.serviceModel>