mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-08 02:30:52 +08:00
feat:furion rbac搭建
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Infrastructure.Enums;
|
||||
|
||||
namespace Yi.Framework.Infrastructure.Exceptions;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Exception"/>类的扩展方法
|
||||
/// </summary>
|
||||
public static class ExceptionExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用 <see cref="ExceptionDispatchInfo.Capture"/> 再次抛出异常
|
||||
/// </summary>
|
||||
/// <param name="exception">Exception to be re-thrown</param>
|
||||
public static void ReThrow(this Exception exception)
|
||||
{
|
||||
ExceptionDispatchInfo.Capture(exception).Throw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取异常中的日志等级
|
||||
/// </summary>
|
||||
/// <param name="exception"></param>
|
||||
/// <param name="defaultLevel"></param>
|
||||
/// <returns></returns>
|
||||
public static LogLevel GetLogLevel(this Exception exception, LogLevel defaultLevel = LogLevel.Error)
|
||||
{
|
||||
return (exception as IHasLogLevel)?.LogLevel ?? defaultLevel;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取异常中的日志错误码
|
||||
/// </summary>
|
||||
/// <param name="exception"></param>
|
||||
/// <param name="defaultLevel"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetLogErrorCode(this Exception exception, ResultCodeEnum defaultCode = ResultCodeEnum.NotSuccess)
|
||||
{
|
||||
return (exception as IHasErrorCode)?.Code ?? (int)defaultCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user