完善邮箱登录,日志完善,操作日志中增加详细报错堆栈信息

This commit is contained in:
2024-01-26 08:17:04 +08:00
parent 0d077bea34
commit 096f8485b4
7 changed files with 109 additions and 6 deletions
@@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using NLog;
using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Routing;
using ZR.Common;
using ZR.Model.System;
using ZR.Service.System.IService;
@@ -50,6 +51,9 @@ namespace ZR.ServiceCore.Middleware
string msg;
string error = string.Empty;
bool notice = true;
var stackTrace = string.Empty;
var controller = context.GetRouteData().Values["Controller"].ToString();
var action = context.GetRouteData().Values["Action"].ToString();
//自定义异常
if (ex is CustomException customException)
{
@@ -57,6 +61,7 @@ namespace ZR.ServiceCore.Middleware
msg = customException.Message;
error = customException.LogMsg;
notice = customException.Notice;
stackTrace = customException.StackTrace;
}
else if (ex is ArgumentException)//参数异常
{
@@ -69,6 +74,7 @@ namespace ZR.ServiceCore.Middleware
error = $"{ex.Message}";
logLevel = LogLevel.Error;
context.Response.StatusCode = 500;
stackTrace = ex.StackTrace;
}
var options = new textJson.JsonSerializerOptions
{
@@ -90,8 +96,10 @@ namespace ZR.ServiceCore.Middleware
RequestMethod = context.Request.Method,
JsonResult = responseResult,
ErrorMsg = string.IsNullOrEmpty(error) ? msg : error,
StackTrace = stackTrace,
OperName = HttpContextExtension.GetName(context),
OperLocation = ip_info.Province + " " + ip_info.City,
Method = controller + "." + action + "()",
OperTime = DateTime.Now,
OperParam = HttpContextExtension.GetRequestValue(context, context.Request.Method)
};