title: How can I tracing method call following the ordering?
body: <p>I would like to tracing the method calls following the order. Because the logging will be applied on the production so I do not want to modify my code so much. </p>
  
  <p>So far, I would like to apply an interceptor on Unity to tracing the method call, I almost done. However, the log printing out is not what I am expecting. All of I need are: </p>
  
  <p>From peusedo code as below:</p>
  
  <pre><code>  void method1()
    {
       call method2();
    }
  </code></pre>
  
  <p>The tracing log should be format as below: </p>
  
  <p>Entering Method call 1/ 
  Entering Method call 2</p>
  
  <p>Leaving Method call 2 /
  Leaving Method call 1</p>
  
  <p>BTW, my application running on .Net framework version 4. </p>
  
  <p>The program as below:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          var container = new UnityContainer();
          container.RegisterType&lt;IInterface1, Implementation1&gt;();
          container.RegisterType&lt;IInterface2, Implementation2&gt;();
          container.RegisterInstance(typeof (IUnityContainer), container);
          container.AddNewExtension&lt;Interception&gt;();
  
          container.Configure&lt;Interception&gt;()
          .SetInterceptorFor&lt;IInterface1&gt;(new InterfaceInterceptor());
  
          container.Configure&lt;Interception&gt;()
          .SetInterceptorFor&lt;IInterface2&gt;(new InterfaceInterceptor());
  
          var service = container.Resolve&lt;IInterface1&gt;();
          var results = service.GetListCustomerIdByName("abc");
  
          Console.ReadLine();
       }
  
  public interface IInterface1
      {
          [Trace]
          IEnumerable&lt;Guid&gt; GetListCustomerIdByName(string name);
      }
  
      public class Implementation1 : IInterface1
      {
          private readonly IInterface2 _impl;
  
          public Implementation1(IUnityContainer container)
          {
              _impl = container.Resolve&lt;IInterface2&gt;();
          }
  
          public IEnumerable&lt;Guid&gt; GetListCustomerIdByName(string name)
          {
              return _impl.GetListCustomerIdByName(name);
          }
      }
  
  public interface IInterface2
  {
      [Trace]
      IEnumerable&lt;Guid&gt; GetListCustomerIdByName(string name);
  }
  
  public class Implementation2 : IInterface2
  {
      public IEnumerable&lt;Guid&gt; GetListCustomerIdByName(string name)
      {
          yield return Guid.NewGuid();
      }
  }
  
  
  public class TraceAttribute : HandlerAttribute
      {
          public override ICallHandler CreateHandler(IUnityContainer container)
          {
              return new TraceCallHandler();
          }
      }
  
  public class TraceCallHandler : ICallHandler
  {
      public IMethodReturn Invoke(IMethodInvocation input, 
     GetNextHandlerDelegate getNext)
      {
          Console.WriteLine("Entering " + input.MethodBase.Name +"()");
  
          InvokeHandlerDelegate next = getNext();
  
          IMethodReturn result = next(input, getNext);
  
          string returnValueStr = 
          result.ReturnValue == null ? "(void)" : result.ReturnValue.ToString();
  
          if (result.Exception != null)
          {
              Console.WriteLine("Exception: {0}", result.Exception);
          }
  
          Console.WriteLine("Leaving 
          " +input.MethodBase.Name + "() Return Value: [" + returnValueStr + "]");
  
          return result;
      }
  
      public int Order { get; set; }
  }
  </code></pre>
  
  <p>Sorry for my code. It is quite long. </p>