title: How to add global error handling in wcf rest service
body: <p>In my web applications I make use of the Application_Error function in global.asax to log all exceptions like so:</p>
  
  <pre><code>void Application_Error(object sender, EventArgs e)
  {
      Exception ex = Server.GetLastError();
  
      while (ex.GetBaseException() != null)
      {
          ex = ex.GetBaseException();
      }
  
      log.writeError(ex.ToString());
  }
  </code></pre>
  
  <p>I've tried similiar in a WCF REST service with no luck.  How would I add global error handling?  I saw <a href="https://stackoverflow.com/questions/6875267/adding-global-error-handling-to-wcf-rest-service">this article</a>, but I'm new to implementing the IServiceBehavior.  Where would I add the above code?</p>