0

I work on a logging project. I want to save parameter values of methods in database. How can I get these values. I want to get parameter value of "Test" method in FirstChanceException event.

class Program
{
    private static void Main(string[] args)
    {
        AppDomain.CurrentDomain.FirstChanceException += CurrentDomain_FirstChanceException;

        Test(100);
    }

    private static void Test(int i)
    {
        throw new OverflowException();
    }

    private static void CurrentDomain_FirstChanceException(object sender,
        System.Runtime.ExceptionServices.FirstChanceExceptionEventArgs e)
    {
        //I Want To Get Parameter Value of Test Method
    }
}
ArMaN
  • 2,306
  • 4
  • 33
  • 55
  • Many other questions about this here on SO...you can't. – Adriano Repetti Oct 16 '14 at 08:08
  • possible duplicate of [Is it possible to get parameters' values for each frame in call stack in .NET](http://stackoverflow.com/questions/819576/is-it-possible-to-get-parameters-values-for-each-frame-in-call-stack-in-net) – Dirk Oct 16 '14 at 08:14

1 Answers1

1

You can do it with PostSharp:

[Serializable] 
public class ExceptionPolicyAttribute : OnExceptionAspect 
{ 
    public override void OnException(MethodExecutionArgs args) 
    { 
        Guid guid = Guid.NewGuid(); 

        Trace.TraceError("Exception {0} handled by ExceptionPolicyAttribute: {1}", 
            guid, args.Exception.ToString()); 

        throw new InternalException( 
            string.Format("An internal exception has occurred. Use the id {0} " + 
            "for further reference to this issue.", guid)); 
    } 
}

The parameter MethodExecutionArgs contains the parameter values that were passed into the failing method call.

qujck
  • 14,388
  • 4
  • 45
  • 74