Files
WCS/Cowain.Base/Helpers/LogAndSwallowAttribute.cs
2026-03-02 09:08:20 +08:00

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; // 吃掉异常
}
}