定时任务,出现异常是将数据推送到系统异常日志以供查看

This commit is contained in:
alex
2023-08-10 10:20:14 +08:00
parent 1bbb30f135
commit 47ab94b3ef
3 changed files with 60 additions and 24 deletions

View File

@@ -1,8 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Claims;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Const;
using JNPF.Common.Security;
using SqlSugar;
namespace Tnb.WarehouseMgr.Entities.Exceptions
@@ -17,28 +20,37 @@ namespace Tnb.WarehouseMgr.Entities.Exceptions
public string UserName { get; set; }
public string RequestURL { get; set; }
public string RequestMethod { get; set; }
public ConnectionConfigOptions options { get; set; }
public ClaimsPrincipal UserIdentity { get; set; }
public ConnectionConfigOptions? options { get; set; }
public TimedTaskException(string message,
string method,
string userId,
string userName,
string requestUrl,
string requestMethod,
ConnectionConfigOptions options,
ClaimsPrincipal userIdentity,
Exception innerException) : base(message, innerException)
{
this.Method = method;
this.UserId = userId;
this.UserName = userName;
this.UserId = userIdentity.FindFirst(ClaimConst.CLAINMUSERID)?.Value ?? string.Empty;
this.UserName = userIdentity.FindFirst(ClaimConst.CLAINMREALNAME)?.Value ?? string.Empty;
this.options = userIdentity.FindFirst(ClaimConst.CONNECTIONCONFIG)?.ToObject<ConnectionConfigOptions>() ?? null;
this.RequestURL = requestUrl;
this.RequestMethod = requestMethod;
this.options = options;
}
}
public static class TimedTaskExceptionExtensions
{
public static TimedTaskException ToTimedTaskException(this Exception exception, ErrorInfo exceptionInfo)
{
TimedTaskException ex = new(exception.Message, exceptionInfo.RequestURL, exceptionInfo.RequestMethod, exceptionInfo.userIdentity, exception);
return ex;
}
}
public class ErrorInfo
{
public string RequestURL { get; set; }
public string RequestMethod { get; set; }
public ClaimsPrincipal userIdentity { get; set; }
}
}