定时任务,出现异常是将数据推送到系统异常日志以供查看
This commit is contained in:
@@ -15,6 +15,7 @@ using JNPF.FriendlyException;
|
||||
using JNPF.Logging;
|
||||
using JNPF.Message.Interfaces.Message;
|
||||
using JNPF.Systems.Entitys.System;
|
||||
using Mapster;
|
||||
using Microsoft.CodeAnalysis.CSharp.Syntax;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Options;
|
||||
@@ -35,7 +36,7 @@ namespace Tnb.WarehouseMgr
|
||||
|
||||
protected override Task ExecuteAsync(CancellationToken stoppingToken) => Task.Run(() =>
|
||||
{
|
||||
//_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||
_eventPublisher = App.GetRequiredService<IEventPublisher>();
|
||||
List<string> toUserIds = new List<string>() { "25398501929509" };
|
||||
//生成任务执行
|
||||
CancellationTokenSource genTaskCTS = new();
|
||||
@@ -64,19 +65,21 @@ namespace Tnb.WarehouseMgr
|
||||
{
|
||||
await action(cts).Catch(async ex =>
|
||||
{
|
||||
if (ex is TimedTaskException timedTaskEx)
|
||||
if (ex is TimedTaskException timedTaskEx and not null)
|
||||
{
|
||||
//await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", options, new SysLogEntity
|
||||
//{
|
||||
// Id = SnowflakeIdHelper.NextId(),
|
||||
// Category = 4,
|
||||
// IPAddress = NetHelper.Ip,
|
||||
// RequestURL = httpRequest.Path,
|
||||
// RequestMethod = httpRequest.Method,
|
||||
// Json = timedTaskEx + "\n" + context.Exception.StackTrace + "\n" + context.Exception.TargetSite.GetParameters().ToString(),
|
||||
// PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
// CreatorTime = DateTime.Now
|
||||
//}));
|
||||
await _eventPublisher.PublishAsync(new LogEventSource("Log:CreateExLog", timedTaskEx.options!, new SysLogEntity
|
||||
{
|
||||
Id = SnowflakeIdHelper.NextId(),
|
||||
Category = 4,
|
||||
UserId = timedTaskEx.UserId,
|
||||
UserName = timedTaskEx.UserName,
|
||||
IPAddress = NetHelper.Ip,
|
||||
RequestURL = timedTaskEx.RequestURL,
|
||||
RequestMethod = timedTaskEx.RequestMethod,
|
||||
Json = timedTaskEx + "\n" + timedTaskEx.InnerException?.StackTrace + "\n" + timedTaskEx?.TargetSite?.GetParameters().ToString(),
|
||||
//PlatForm = string.Format("{0}-{1}", userAgent.OS.ToString(), userAgent.RawValue),
|
||||
CreatorTime = DateTime.Now
|
||||
}));
|
||||
}
|
||||
});
|
||||
await Task.Delay(1000);
|
||||
|
||||
Reference in New Issue
Block a user