【优化】调整全局异常处理器及过滤器异常日志存储名称问题,日志记录更加详细直观,同时修改类命名。

This commit is contained in:
大灰灰
2022-10-14 00:31:57 +08:00
parent f723defa85
commit 5351657cad
5 changed files with 10 additions and 10 deletions

View File

@@ -36,7 +36,7 @@ namespace CoreCms.Net.Filter
public void OnException(ExceptionContext context)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Web, "全局异常", "全局捕获异常", context.Exception);
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Web, "全局异常", context.Exception.Message, context.Exception);
HttpStatusCode status = HttpStatusCode.InternalServerError;

View File

@@ -36,7 +36,7 @@ namespace CoreCms.Net.Filter
public void OnException(ExceptionContext context)
{
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Web, "全局异常", "全局捕获异常", context.Exception);
NLogUtil.WriteAll(NLog.LogLevel.Error, LogType.Web, "全局异常", context.Exception.Message, context.Exception);
HttpStatusCode status = HttpStatusCode.InternalServerError;

View File

@@ -26,11 +26,11 @@ namespace CoreCms.Net.Middlewares;
/// <summary>
/// 异常错误统一返回记录
/// </summary>
public class ExceptionHandlerMiddForAdmin
public class ExceptionHandlerMiddlewareForAdmin
{
private readonly RequestDelegate _next;
public ExceptionHandlerMiddForAdmin(RequestDelegate next)
public ExceptionHandlerMiddlewareForAdmin(RequestDelegate next)
{
_next = next;
}
@@ -50,7 +50,7 @@ public class ExceptionHandlerMiddForAdmin
private async Task HandleExceptionAsync(HttpContext context, Exception ex)
{
if (ex == null) return;
NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "全局捕获异常", "全局捕获异常", new Exception("全局捕获异常", ex));
NLogUtil.WriteAll(LogLevel.Error, LogType.Web, "全局捕获异常", ex.Message, ex);
await WriteExceptionAsync(context, ex).ConfigureAwait(false);
}

View File

@@ -26,12 +26,12 @@ namespace CoreCms.Net.Middlewares;
/// <summary>
/// 异常错误统一返回记录
/// </summary>
public class ExceptionHandlerMiddForClent
public class ExceptionHandlerMiddlewareForClent
{
private readonly RequestDelegate _next;
public ExceptionHandlerMiddForClent(RequestDelegate next)
public ExceptionHandlerMiddlewareForClent(RequestDelegate next)
{
_next = next;
}
@@ -52,7 +52,7 @@ public class ExceptionHandlerMiddForClent
{
if (ex == null) return;
NLogUtil.WriteAll(LogLevel.Error, LogType.ApiRequest, "全局捕获异常", "全局捕获异常", new Exception("全局捕获异常", ex));
NLogUtil.WriteAll(LogLevel.Error, LogType.ApiRequest, "全局捕获异常", ex.Message, ex);
await WriteExceptionAsync(context, ex).ConfigureAwait(false);
}

View File

@@ -38,7 +38,7 @@ namespace CoreCms.Net.Middlewares
/// <returns></returns>
public static IApplicationBuilder UseExceptionHandlerMiddForAdmin(this IApplicationBuilder app)
{
return app.UseMiddleware<ExceptionHandlerMiddForAdmin>();
return app.UseMiddleware<ExceptionHandlerMiddlewareForAdmin>();
}
/// <summary>
@@ -48,7 +48,7 @@ namespace CoreCms.Net.Middlewares
/// <returns></returns>
public static IApplicationBuilder UseExceptionHandlerMiddForClent(this IApplicationBuilder app)
{
return app.UseMiddleware<ExceptionHandlerMiddForClent>();
return app.UseMiddleware<ExceptionHandlerMiddlewareForClent>();
}
/// <summary>