title: Log error in wcf with message body in elmah
body: <p>I have a WCF service that handles requests from microcontrollers running c. Most of the time this goes well, and in case something goes wrong I have setup elmah to log errors that occur in the WCF service. This works fine when the error happens inside the WCF service (ex database errors), but when the WCF service receives data that is not valid json the error log is not very useful. I get errors like</p>
  
  <blockquote>
    <p>System.FormatException.
    Encountered invalid character ''.</p>
  </blockquote>
  
  <p>and</p>
  
  <blockquote>
    <p>System.Xml.XmlException
    Encountered unexpected character '.'.</p>
  </blockquote>
  
  <p>This lets me know that something went wrong, but I would like to see the raw json to know what the message looked like, so I can fix the errors in the microcontrollers. Is this possible?</p>
  
  <p>The interface to the service looks like:</p>
  
  <pre><code>    [ServiceContract]
  public interface IDevCom
  {
      [OperationContract, WebInvoke(ResponseFormat = WebMessageFormat.Json,
      RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
      ConnectResult Connect(ConnectParameter parameter);
  }
  </code></pre>
  
  <p>The current error handler looks like</p>
  
  <pre><code>    public class HttpErrorHandler : IErrorHandler
  {
      public bool HandleError(Exception error)
      {
          try
          {
              ExceptionUtility.LogException( error, nameof(HttpErrorHandler));
          }
          finally
          {
          }
          return true;
      }
  
      public void ProvideFault(Exception error, MessageVersion version, ref Message fault)
      {
          if (error != null) //Notify ELMAH of the exception
          {
              if (System.Web.HttpContext.Current == null)
                  return;
              Elmah.ErrorSignal.FromCurrentContext().Raise(error);
          }
      }
  }
  </code></pre>