From 90467c926b0bbca732e2ef1215b0aa6b6fd6b190 Mon Sep 17 00:00:00 2001 From: zhangxiaofeng <1939543722@qq.com> Date: Tue, 29 Oct 2024 00:05:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8B=A6=E6=88=AAFilter?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Filters/GlobalExceptionsFilter.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Filters/GlobalExceptionsFilter.cs b/ds-wms-service/DS.Module.Core/Filters/GlobalExceptionsFilter.cs index 6060a5ab..b048999c 100644 --- a/ds-wms-service/DS.Module.Core/Filters/GlobalExceptionsFilter.cs +++ b/ds-wms-service/DS.Module.Core/Filters/GlobalExceptionsFilter.cs @@ -22,7 +22,7 @@ public class GlobalExceptionsFilter : IExceptionFilter private readonly SqlSugarScope db; public GlobalExceptionsFilter(IHostingEnvironment env, IServiceProvider serviceProvider) { - _env = env; + _env = env; _serviceProvider = serviceProvider; db = (SqlSugarScope)_serviceProvider.GetRequiredService(); } @@ -56,13 +56,17 @@ public class GlobalExceptionsFilter : IExceptionFilter #region 写入日志库 - var className = context.Exception.TargetSite.DeclaringType?.FullName; - var groupCollection = Regex.Match(className, "<(.*?)>").Groups; - var methodName = ""; - if (groupCollection.Count > 1) + string? methodName = ""; + string? className = context.Exception.TargetSite?.DeclaringType?.FullName ?? ""; + if (!string.IsNullOrEmpty(className)) { - methodName = groupCollection[1].Value; + var groupCollection = Regex.Match(className, "<(.*?)>").Groups; + if (groupCollection.Count > 1) + { + methodName = groupCollection[1].Value; + } } + var exLog = new SysLogException() { ClassName = className,