异常拦截Filter报错问题处理

dev
zhangxiaofeng 4 weeks ago
parent f3b0351eb7
commit 90467c926b

@ -22,7 +22,7 @@ public class GlobalExceptionsFilter : IExceptionFilter
private readonly SqlSugarScope db; private readonly SqlSugarScope db;
public GlobalExceptionsFilter(IHostingEnvironment env, IServiceProvider serviceProvider) public GlobalExceptionsFilter(IHostingEnvironment env, IServiceProvider serviceProvider)
{ {
_env = env; _env = env;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
db = (SqlSugarScope)_serviceProvider.GetRequiredService<ISqlSugarClient>(); db = (SqlSugarScope)_serviceProvider.GetRequiredService<ISqlSugarClient>();
} }
@ -56,13 +56,17 @@ public class GlobalExceptionsFilter : IExceptionFilter
#region 写入日志库 #region 写入日志库
var className = context.Exception.TargetSite.DeclaringType?.FullName; string? methodName = "";
var groupCollection = Regex.Match(className, "<(.*?)>").Groups; string? className = context.Exception.TargetSite?.DeclaringType?.FullName ?? "";
var methodName = ""; if (!string.IsNullOrEmpty(className))
if (groupCollection.Count > 1)
{ {
methodName = groupCollection[1].Value; var groupCollection = Regex.Match(className, "<(.*?)>").Groups;
if (groupCollection.Count > 1)
{
methodName = groupCollection[1].Value;
}
} }
var exLog = new SysLogException() var exLog = new SysLogException()
{ {
ClassName = className, ClassName = className,

Loading…
Cancel
Save