3. Implementation/WCF

WCF Tracing and Message Logging

SSKK 2014. 5. 20. 05:56

Really I did ridiculous thing. 


Our system showed "Server too busy" exception so I wanted to trace the log messages of the WCF services. I followed lots of instructions for that. 



And the critical thing was as below:


  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="C:\logs\Traces.svclog" />
  </sharedListeners>


After restarting our service, I refreshed the windows explorer to check if the log file was created but it didn't. 


The reason was very simple. The log file couldn't be created if the destination folder does not exist. So only after creating the 'c:\logs' folder, my concern was removed.



MSDN offers the recommended settings for tracing and message logging

(http://msdn.microsoft.com/en-us/library/aa702726(v=vs.110).aspx)



  • Recommnded Settings for a Production Environment

<configuration>
 <system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Warning"
            propagateActivity="true" >
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="myUserTraceSource"
            switchValue="Warning, ActivityTracing">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="C:\logs\Traces.svclog" />
  </sharedListeners>
 </system.diagnostics>

<system.serviceModel>
  <diagnostics wmiProviderEnabled="true">
  </diagnostics>
 </system.serviceModel>
</configuration>

  • Recommended Settings for Deployment or Debugging
configuration>
 <system.diagnostics>
  <sources>
    <source name="System.ServiceModel"
            switchValue="Information, ActivityTracing"
            propagateActivity="true" >
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="System.ServiceModel.MessageLogging">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
    <source name="myUserTraceSource"
            switchValue="Information, ActivityTracing">
      <listeners>
        <add name="xml"/>
      </listeners>
    </source>
  </sources>
  <sharedListeners>
    <add name="xml"
         type="System.Diagnostics.XmlWriterTraceListener"
               initializeData="C:\logs\Traces.svclog" />
  </sharedListeners>
 </system.diagnostics>

 <system.serviceModel>
  <diagnostics wmiProviderEnabled="true">
      <messageLogging 
           logEntireMessage="true" 
           logMalformedMessages="true"
           logMessagesAtServiceLevel="true" 
           logMessagesAtTransportLevel="true"
           maxMessagesToLog="3000" 
       />
  </diagnostics>
 </system.serviceModel>
</configuration>

To see the logs, use the service trace viewer tool!
(C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin\SvcTraceViewer.exe)

(http://msdn.microsoft.com/en-us/library/ms732023(v=vs.110).aspx)