How to Enable Tracing in WCF?

How to Enable Tracing in WCF?
WCF Service is definitely an exciting thing to work with. I have been working for a while now and find it challenging and adventurous.  There have been instances when you are trying to consume your WCF Service from a Windows Forms Application, WPF Applications and even from Console Applications, you get weird error message which can be difficult to make sense. There is a better way to understand those error messages. You can enable WCF Tracing and that will give you more specific and elaborate error messages.  Here I intend to show how to enable tracing in WCF Services.


Let me show 2 ways I know of to enable Tracing in WCF, one is using the Service Configuration Editor and the other is by editing the config file yourself.

Method 1: Using the Service Configuration Editor

Step 1:   Go to Start à All Programs à Microsoft Visual Studio 2010 à Microsoft Windows SDK Tools 
à Service Configuration Editor.


Step 2:  Open your App.config or the Web.config file of your project. You should see the window as
               shown below.

Step 3:    Select the Diagnostics Folder from the left panel and click on Enable Tracing to Enable the
                Tracing as shown in the diagram above with the arrow.  You can also change the Trace Level if               
                you want.


Method 2: Editing the config file

The other way to enable WCF Tracing  is just by editing your config file. Open the config file in any editor Visual Studio or Notepad and just add the following node to it.





      <source name="System.ServiceModel"




          <add name="ServiceModelTraceListener"

               type="System.Diagnostics.XmlWriterTraceListener, System, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"









Use SvcTraceViewer.exe to view the Trace log:

Now that you have enabled tracing, you should be able to view the Trace file for more error information.  The Trace files by default get written to your Debug folder under your bin folder.


Microsoft provides a viewer called the SvcTraceViewer.exe to view your Trace files.  You should be able to find your SvcTraceViewer.exe at this location.


\\Program Files\\Microsoft SDKs\\Windows\\v6.0A\\bin


Now you can open the trace file which should be named something like wcf-traces.svclog and you can find it in the bin\\Debug folder of your Project or under that folder that you have specified in the config file.  The errors should be highlight in red as shown below.




Now you can explore your error message and fix it.


Hope that was useful!