title: Best way to measure the execution time of methods
body: <p>I'm trying to find the best way to measure the duration of a method to log them on Application Insights, I know it's possible if we do something like this:</p>
  
  <pre><code>public void TestMethod()
  {    
      var sw = Stopwatch.StartNew();
  
      //code here
  
      sw.Stop();
      Console.WriteLine("Time elapsed: {0}", sw.Elapsed);
  }
  </code></pre>
  
  <p>But, as you suppose, I don't want to write it on all the methods, ideally, I want to use a decorator, something similar to this. </p>
  
  <pre><code>[MeasureTime]
  public void TestMethod()
  {
      //code here
  }
  </code></pre>
  
  <p>Or something similar. So my question is: How can I build something like this? Is there a better way to do it?</p>
  
  <p>Thanks in advance!</p>