diff --git a/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs b/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs index b148d6f..e2f000c 100644 --- a/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs +++ b/Falcon.SugarApi/ApiDefinistions/ApiControllerBase.cs @@ -62,10 +62,12 @@ namespace Falcon.SugarApi.ApiDefinistions /// 响应信息类型 /// 请求数据 /// 响应数据 - protected virtual void SaveLogger(TRequest data, TResponse result) { + /// 异常 + protected virtual void SaveLogger(TRequest data, TResponse result, Exception? exception = null) { var requestStr = this.JsonSerialize(data); var responseStr = this.JsonSerialize(result); - var logmsg = $"{this.Prefix}\n请求消息:{requestStr}\n响应消息{responseStr}"; + var exStr = exception == null ? "" : exception.ToString(); + var logmsg = $"{this.Prefix}\n请求消息:{requestStr}\n响应消息:{responseStr}\n异常:{exStr}\n"; this.Logger.LogInformation(logmsg); } @@ -86,7 +88,7 @@ namespace Falcon.SugarApi.ApiDefinistions /// 对象的类型 /// json字符串 /// 对象实例 - protected T? JsonDeserialize(string json) where T: class { + protected T? JsonDeserialize(string json) where T : class { return JsonSerializer.Deserialize(json); }