记录日志增加异常日志

This commit is contained in:
falcon 2022-09-09 15:04:38 +08:00
parent 5dddabe868
commit 2891a0d83b

View File

@ -62,10 +62,12 @@ namespace Falcon.SugarApi.ApiDefinistions
/// <typeparam name="TResponse">响应信息类型</typeparam>
/// <param name="data">请求数据</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 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);
}