14 lines
523 B
C#
14 lines
523 B
C#
using MethodBoundaryAspect.Fody.Attributes;
|
|
|
|
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly)]
|
|
public sealed class LogAndSwallowAttribute : OnMethodBoundaryAspect
|
|
{
|
|
// 可全局统一处理,也能自定义
|
|
public static Action<Exception>? OnExceptionAction { get; set; }
|
|
|
|
public override void OnException(MethodExecutionArgs args)
|
|
{
|
|
OnExceptionAction?.Invoke(args.Exception);
|
|
args.FlowBehavior = FlowBehavior.Return; // 吃掉异常
|
|
}
|
|
} |