title: How do I intercept a method call in C#?
body: <p>For a given class I would like to have tracing functionality i.e. I would like to log every method call (method signature and actual parameter values) and every method exit (just the method signature).    </p>
  
  <p>How do I accomplish this assuming that:  </p>
  
  <ul>
  <li>I don't want to use any 3rd party
  AOP libraries for C#,</li>
  <li>I don't want to add duplicate code to all the methods that I want to trace,  </li>
  <li>I don't want to change the public API of the class - users of the class should be able to call all the methods in exactly the same way.  </li>
  </ul>
  
  <p>To make the question more concrete let's assume there are 3 classes:  </p>
  
  <pre><code> public class Caller 
   {
       public static void Call() 
       {
           Traced traced = new Traced();
           traced.Method1();
           traced.Method2(); 
       }
   }
  
   public class Traced 
   {
       public void Method1(String name, Int32 value) { }
  
       public void Method2(Object object) { }
   }
  
   public class Logger
   {
       public static void LogStart(MethodInfo method, Object[] parameterValues);
  
       public static void LogEnd(MethodInfo method);
   }
  </code></pre>
  
  <p>How do I invoke <em>Logger.LogStart</em> and <em>Logger.LogEnd</em> for every call to <em>Method1</em> and <em>Method2</em> without modifying the <em>Caller.Call</em> method and without adding the calls explicitly to <em>Traced.Method1</em> and <em>Traced.Method2</em>?</p>
  
  <p>Edit:  What would be the solution if I'm allowed to slightly change the Call method?</p>