title: How do I detect and log the parameter names and values in the method signature of a delegate?
body: <p>Thanks for looking!</p>
  <h1>Background</h1>
  <p>I have an extension method that is used to wrap a given method in a <code>try/catch</code> and I am adding code for logging any caught exceptions:</p>
  <pre><code> public static T HandleServerError&lt;T&gt;(this Func&lt;T&gt; func)
          {
              T result = default(T);
              try
              {
                  result = func();
              }
              catch (Exception ex)
              {
                  //******************************
                  //Code for logging will go here.
                  //******************************
  
                  ErrorHandlers.ThrowServerErrorException(ex);
              }
  
              return result;
          }
  </code></pre>
  <p>Here is how the method is called:</p>
  <pre><code>var result = new Func&lt;SomeClass.SomeType&gt;(() =&gt; SomeClass.SomeMethod(id, name, color, quantity)).HandleServerError();
  return result;
  </code></pre>
  <p>As you can see, whatever method I am calling is injected into the extension method and executed inside the try/catch.</p>
  <p>We will be using NLog or ELMAH for logging, but that is largely irrelevant to this question.</p>
  <h1>Problem</h1>
  <p>If something goes wrong, I need to log as much information about the delegated method as possible since things like &quot;Object reference not set to an instance of an object&quot; is not in itself helpful.</p>
  <p>I would like to log the class and name of the method being called as well as the parameters in the method signature along with their values.  If possible, I would even like to log which line failed, and finally the actual stack trace.</p>
  <p>I am guessing that I need to use reflection for this and maybe catch the binding flags somehow as the injected method executes but I am not entirely sure if that is the best approach or if it is even feasible.</p>
  <h1>Question</h1>
  <p>Using C#, how do I get the meta information (i.e. method name, class of origin, parameters, parameter values) about an injected/delegated method?</p>
  <p>Thanks in advance.</p>