From fc09e930148fc5b844f4bdc2bf02ff90f20217fe Mon Sep 17 00:00:00 2001 From: huangye <381538764@qq.com> Date: Tue, 24 Dec 2024 16:01:48 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E8=A7=A3=E5=86=B3=E5=AE=9A?= =?UTF-8?q?=E6=97=B6=E4=BB=BB=E5=8A=A1=E7=9B=91=E5=90=AC=E5=88=B0=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=97=B6=EF=BC=8C=E4=B8=94=E9=85=8D=E7=BD=AE=E4=B8=8D?= =?UTF-8?q?=E5=8F=91=E9=80=81=E9=82=AE=E4=BB=B6=EF=BC=8C=E6=9C=AC=E5=9C=B0?= =?UTF-8?q?Log=E8=83=BD=E8=AE=B0=E5=BD=95=E5=88=B0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin.NET.Core/Service/Job/JobMonitor.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs b/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs index 318cade9..d03deeee 100644 --- a/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs +++ b/Admin.NET/Admin.NET.Core/Service/Job/JobMonitor.cs @@ -13,12 +13,14 @@ public class JobMonitor : IJobMonitor { private readonly IEventPublisher _eventPublisher; private readonly SysConfigService _sysConfigService; + private readonly ILogger _logger; public JobMonitor(IServiceScopeFactory scopeFactory) { var serviceScope = scopeFactory.CreateScope(); _sysConfigService = serviceScope.ServiceProvider.GetRequiredService(); - _eventPublisher = serviceScope.ServiceProvider.GetRequiredService(); ; + _eventPublisher = serviceScope.ServiceProvider.GetRequiredService(); + _logger = serviceScope.ServiceProvider.GetRequiredService>(); ; } public Task OnExecutingAsync(JobExecutingContext context, CancellationToken stoppingToken) @@ -28,11 +30,19 @@ public class JobMonitor : IJobMonitor public async Task OnExecutedAsync(JobExecutedContext context, CancellationToken stoppingToken) { - // 将异常作业发送到邮件 - if (await _sysConfigService.GetConfigValueByCode(ConfigConst.SysErrorMail) && context.Exception != null) + if (context.Exception != null) { var errorInfo = $"【{context.Trigger.Description}】定时任务错误:{context.Exception}"; - await _eventPublisher.PublishAsync(CommonConst.SendErrorMail, errorInfo, stoppingToken); + if (await _sysConfigService.GetConfigValueByCode(ConfigConst.SysErrorMail)) + { + // 将异常作业发送到邮件 + await _eventPublisher.PublishAsync(CommonConst.SendErrorMail, errorInfo, stoppingToken); + } + else + { + //将异常信息存储本地记录 + _logger.LogError(errorInfo); + } } } } \ No newline at end of file