我在一个日志项目上工作。我想保存数据库中方法的参数值。我怎样才能获得这些值。我想得到参数值"测试" FirstChanceException事件中的方法。
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
}
}
答案 0 :(得分:1)
您可以使用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));
}
}
参数MethodExecutionArgs
包含传递给失败方法调用的参数值。