이 문제를 해결할 수있는 방법은 두 가지가 있습니다.
A. 이미 기록 된 예외를 저장하려면 스레드 정적 필드를 사용하십시오.
[Serializable]
public class MyAspect : OnExceptionAspect
{
[ThreadStatic]
private static Exception lastException;
public override void OnException(MethodExecutionArgs args)
{
if(args.Exception != lastException)
{
string msg = string.Format("{0} had an error @ {1}: {2}\n{3}",
args.Method.Name, DateTime.Now,
args.Exception.Message, args.Exception.StackTrace);
Trace.WriteLine(msg);
lastException = args.Exception;
}
}
}
B. 예외 객체에 태그를 추가하십시오.
[Serializable]
public class MyAspect : OnExceptionAspect
{
private static object marker = new object();
public override void OnException(MethodExecutionArgs args)
{
if(!args.Exception.Data.Contains(marker))
{
string msg = string.Format("{0} had an error @ {1}: {2}\n{3}",
args.Method.Name, DateTime.Now,
args.Exception.Message, args.Exception.StackTrace);
Trace.WriteLine(msg);
args.Exception.Data.Add(marker, marker);
}
}
}
의도 한 행동은 무엇입니까? 그 점에 대해 당신은 분명하지 않습니다. –
사과. 예외 지점에서 메서드의 스택 추적 및 매개 변수를 기록 할 수 있어야합니다. 그러나 나는 또한 예외적으로 다시 로깅하지 않고 정상적인 스택처럼 전파하기를 원한다. –