WCF Tracing in Windows Azure SDK 1.3 or higher

  • WCF Tracing in on-premise servers - https://msdn.microsoft.com/en-us/library/ms733025.aspx
  • WCF Tracing in on-premise servers with intermittent failures – Enable Circular tracing: https://msdn.microsoft.com/en-us/library/aa395205.aspx
  •  WCF Tracing in Azure:
    • As most of you already know, WCF Service Web Role implements WCF tracing by default and puts it in the local storage. However, it's disabled by default. All you have to do to enable is to uncomment certain configuration in web.config as shown below.
      •  Change <system.diagnostics> tag from:

<!--<system.diagnostics>    

    <sharedListeners>

      <add name="AzureLocalStorage" type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"/>

    </sharedListeners>

    <sources>

      <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">

        <listeners>

          <add name="AzureLocalStorage"/>

        </listeners>

      </source>

      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">

        <listeners>

          <add name="AzureLocalStorage"/>

        </listeners>

      </source>

    </sources>

  </system.diagnostics>-->

  <system.diagnostics>

    <trace autoflush="true">

      <listeners>

        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

          name="AzureDiagnostics">

          <filter type="" />

        </add>

      </listeners>

    </trace>

  </system.diagnostics>

 

      • To:

  <system.diagnostics>    

    <sharedListeners>

      <add name="AzureLocalStorage" type="WCFServiceWebRole1.AzureLocalStorageTraceListener, WCFServiceWebRole1"/>

    </sharedListeners>

    <sources>

      <source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">

        <listeners>

          <add name="AzureLocalStorage"/>

        </listeners>

      </source>

      <source name="System.ServiceModel.MessageLogging" switchValue="Verbose">

        <listeners>

          <add name="AzureLocalStorage"/>

        </listeners>

      </source>

    </sources>

    <trace autoflush="true">

      <listeners>

        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

          name="AzureDiagnostics">

          <filter type="" />

        </add>

      </listeners>

    </trace>

  </system.diagnostics>

 

      • And add the diagnostics tag in <system.servicemodel>

<system.serviceModel>

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

      </diagnostics>

    <behaviors>

……………………

 

  • Now, what if you decided to deploy the WCF service web role without enabling WCF trace in the local storage? The answer is, we can still enable WCF tracing like any other non-Azure application and write it on the web/worker role. Here’s the configuration:

   <system.diagnostics>

    <sources>

      <source name="System.ServiceModel" switchValue="Information,ActivityTracing,Warning" propagateActivity="true">

        <listeners>

          <add name="xml" />

        </listeners>

      </source>

      <source name="System.ServiceModel.MessageLogging">

        <listeners>

          <add name="xml" />

        </listeners>

      </source>

    </sources>

    <sharedListeners>

      <add initializeData="C:\CTS\WCFTrace.svclog" type="System.Diagnostics.XmlWriterTraceListener"

        name="xml" />

    </sharedListeners>

    <trace autoflush="true" >

      <listeners>

        <add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

          name="AzureDiagnostics">

          <filter type="" />

        </add>

      </listeners>

    </trace>

  </system.diagnostics>

 

  <system.serviceModel>

    <diagnostics>

 

      <messageLogging logEntireMessage="true"

                      maxMessagesToLog="300"

                      logMessagesAtServiceLevel="true"

                      logMalformedMessages="true"

                      logMessagesAtTransportLevel="true" />

    </diagnostics>

    <behaviors>…………………………

 

However, the trace will not be generated just with the above configuration. If you run procmon, you would see “Access Denied” on CreateFile for “C:\CTS\WCFTrace.svclog” that I’ve in the configuration for logging WCF trace. Open up task manager and you would see w3wp.exe (remember – it’s full IIS) running under Network Service account. This account needs to have permissions to write on the folder configured to store WCF traces. Just give “Everyone” write permissions on the folder and get it to work!!

Since regular tracing works, I don’t expect any issues running circular (rolling) tracing in the Azure environment.