title: Logging errors in WCF - Nothing being stored in log file when exception is being thrown
body: <p>I've been trying to catch exceptions in my WCF service and store them in a log file (I don't want the client to get any specific error message at this point).</p>
  
  <p>Having read a few tutorials online I've added some logging configuration to the <code>&lt;system.diagnostics&gt;</code> section of web.config:</p>
  
  <pre><code>&lt;sources&gt;
    &lt;source name="System.ServiceModel.MessageLogging" switchValue="Error"&gt;
      &lt;listeners&gt;
        &lt;add type="System.Diagnostics.DefaultTraceListener" name="Default"&gt;
          &lt;filter type="" /&gt;
        &lt;/add&gt;
        &lt;add name="ServiceModelMessageLoggingListener"&gt;
          &lt;filter type="" /&gt;
        &lt;/add&gt;
      &lt;/listeners&gt;
    &lt;/source&gt;
    &lt;source name="System.ServiceModel" switchValue="Error" propagateActivity="true"&gt;
      &lt;listeners&gt;
        &lt;add type="System.Diagnostics.DefaultTraceListener" name="Default"&gt;
          &lt;filter type="" /&gt;
        &lt;/add&gt;
        &lt;add name="ServiceModelTraceListener"&gt;
          &lt;filter type="" /&gt;
        &lt;/add&gt;
      &lt;/listeners&gt;
    &lt;/source&gt;
  &lt;/sources&gt;    
  &lt;sharedListeners&gt;
    &lt;add initializeData="C:\inetpub\wwwroot\myApp\logs\Web_messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp"&gt;
      &lt;filter type="" /&gt;
    &lt;/add&gt;
    &lt;add initializeData="C:\inetpub\wwwroot\myApp\logs\Web_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp"&gt;
      &lt;filter type="" /&gt;
    &lt;/add&gt;
  &lt;/sharedListeners&gt;
  </code></pre>
  
  <p>In the event of an exception I've been tried using Debug.WriteLine and Trace.WriteLine but nothing is getting written to the tracefile.</p>
  
  <p>I know IIS / WCF can write to the log file, if I set the switchValue for either of the sources to be Verbose I get plenty of information (too much to be of use), but I only want the exception code.</p>