记录日志增加异常日志
This commit is contained in:
parent
5dddabe868
commit
2891a0d83b
|
@ -62,10 +62,12 @@ namespace Falcon.SugarApi.ApiDefinistions
|
||||||
/// <typeparam name="TResponse">响应信息类型</typeparam>
|
/// <typeparam name="TResponse">响应信息类型</typeparam>
|
||||||
/// <param name="data">请求数据</param>
|
/// <param name="data">请求数据</param>
|
||||||
/// <param name="result">响应数据</param>
|
/// <param name="result">响应数据</param>
|
||||||
protected virtual void SaveLogger<TRequest, TResponse>(TRequest data, TResponse result) {
|
/// <param name="exception">异常</param>
|
||||||
|
protected virtual void SaveLogger<TRequest, TResponse>(TRequest data, TResponse result, Exception? exception = null) {
|
||||||
var requestStr = this.JsonSerialize(data);
|
var requestStr = this.JsonSerialize(data);
|
||||||
var responseStr = this.JsonSerialize(result);
|
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);
|
this.Logger.LogInformation(logmsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,7 +88,7 @@ namespace Falcon.SugarApi.ApiDefinistions
|
||||||
/// <typeparam name="T">对象的类型</typeparam>
|
/// <typeparam name="T">对象的类型</typeparam>
|
||||||
/// <param name="json">json字符串</param>
|
/// <param name="json">json字符串</param>
|
||||||
/// <returns>对象实例</returns>
|
/// <returns>对象实例</returns>
|
||||||
protected T? JsonDeserialize<T>(string json) where T: class {
|
protected T? JsonDeserialize<T>(string json) where T : class {
|
||||||
return JsonSerializer.Deserialize<T>(json);
|
return JsonSerializer.Deserialize<T>(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user