title: Exception handling and logging in asp.net web api
body: <p>I am new to ASP.NET web api and I was reading these two article about exception handling</p>
  
  <ol>
  <li><a href="https://www.asp.net/web-api/overview/error-handling/exception-handling" rel="nofollow noreferrer">Exception handling</a></li>
  <li><a href="https://www.asp.net/web-api/overview/error-handling/web-api-global-error-handling" rel="nofollow noreferrer">Error handling</a></li>
  </ol>
  
  <p>While I understand <a href="https://www.asp.net/web-api/overview/error-handling/exception-handling" rel="nofollow noreferrer">Exception handling</a> link, I am not sure about using  <a href="https://www.asp.net/web-api/overview/error-handling/web-api-global-error-handling" rel="nofollow noreferrer">Error handling</a>. Here is what I want to do:</p>
  
  <ol>
  <li>when an error occurs, I want to log that error with message, stack trace &amp; request object that was sent with the original request.  </li>
  <li>The type of every incoming request can be different &amp; I am planning to serialize the request object into JSON string and store them in DB while error logging. </li>
  </ol>
  
  <p>It seems like I should add try catch block on every method and then perform the exception handling and logging. This will be a tedious task. Is there any way to globally handle error and still able to capture exceptions details (message, stack trace) &amp; log request object.</p>