using System.Runtime.ExceptionServices; using Microsoft.Extensions.Logging; using Yi.Framework.Infrastructure.Enums; namespace Yi.Framework.Infrastructure.Exceptions; /// /// 类的扩展方法 /// public static class ExceptionExtensions { /// /// 使用 再次抛出异常 /// /// Exception to be re-thrown public static void ReThrow(this Exception exception) { ExceptionDispatchInfo.Capture(exception).Throw(); } /// /// 获取异常中的日志等级 /// /// /// /// public static LogLevel GetLogLevel(this Exception exception, LogLevel defaultLevel = LogLevel.Error) { return (exception as IHasLogLevel)?.LogLevel ?? defaultLevel; } /// /// 获取异常中的日志错误码 /// /// /// /// public static int GetLogErrorCode(this Exception exception, ResultCodeEnum defaultCode = ResultCodeEnum.NotSuccess) { return (exception as IHasErrorCode)?.Code ?? (int)defaultCode; } }