title: What is the clean way to Implement Audit Trail in Asp.net MVC and Web API
body: <p>I am trying to look for a more clean way to add audit trail function to an exist asp.net MVC and Web Api project which contains hundreds of <code>Controller</code> and <code>ApiController</code>.</p>
  
  <p>The Audit trail log would look like below. Basically I just want to log <code>In what time who did what</code> in this function. </p>
  
  <pre><code>UserID
  
  ActionTime
  
  Controller 
  
  Action
  </code></pre>
  
  <p>Anything I missed ? If there is . Please correct me. Thanks.</p>
  
  <p>Currently I found there are some ways to make it .</p>
  
  <ol>
  <li><p>Implement an <code>ActionFilterAttribute</code> and write my own log function in the <code>OnActionExecuting</code>, and then decorate all the actions with this attribute. </p></li>
  <li><p>Implement a base <code>Controller</code> like <code>BaseController</code> for all the exist controller. And write log in the <code>OnActionExecuting</code>. Then change all the controller to inherit from <code>BaseController</code>. (If it is wrong . Please correct me . Thanks.)</p></li>
  <li><p>For the <code>ApiController</code>. Implement a <code>DelegatingHandler</code> to make it.</p></li>
  </ol>
  
  <p>For 1 and 2. I need change to all the exist code to make it. like change base class or decorate with new attribute. Considering in my case, This will be a hard work. Because thousands of class or methods need to be changed . I thinks it is kind of verbose. So I wondered if there is some clean way like 3 for ApiController to make it. Thanks.</p>