mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-26 19:57:55 +08:00
添加dto模式的demo测试
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Runtime.ExceptionServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Yi.Framework.Common.Enum;
|
||||
|
||||
namespace Yi.Framework.Common.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 ResultCodeEnum GetLogErrorCode(this Exception exception, ResultCodeEnum defaultCode = ResultCodeEnum.NotSuccess)
|
||||
{
|
||||
return (exception as IHasErrorCode)?.Code ?? defaultCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user