From 9a7091b4e07925a50ee894e33c7db5426c82caf1 Mon Sep 17 00:00:00 2001 From: cheche <717840555@qq.com> Date: Tue, 19 Mar 2024 18:36:14 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=88=A0=E9=99=A4=E6=97=A5=E5=BF=97try?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CommonJobs/DelApiLogTaskJob.cs | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/CommonJobs/DelApiLogTaskJob.cs b/Src/Dlhis.ScheduledTask/CommonJobs/DelApiLogTaskJob.cs index 50126b15..d623561b 100644 --- a/Src/Dlhis.ScheduledTask/CommonJobs/DelApiLogTaskJob.cs +++ b/Src/Dlhis.ScheduledTask/CommonJobs/DelApiLogTaskJob.cs @@ -7,25 +7,35 @@ namespace Dlhis.ScheduledTask.CommonJobs; public class DelApiLogTaskJob { private readonly IDbContext _dbContext; + private readonly Logger _logger; - public DelApiLogTaskJob(IDbContext dbContext) + public DelApiLogTaskJob(IDbContext dbContext, Logger logger) { _dbContext = dbContext; + _logger = logger; } public async Task RunAsync() { - DateTime now = DateTime.Now; - DateTime todayStart = now.Date; - DateTime threeDaysAgoStart = todayStart.AddDays(-3); + try + { + DateTime now = DateTime.Now; + DateTime todayStart = now.Date; + DateTime threeDaysAgoStart = todayStart.AddDays(-3); - var logs = await _dbContext.ChangeDb("log") - .Queryable() - .Where(x => x._ts<= threeDaysAgoStart) - .OrderBy(x =>x._ts,OrderByType.Asc) - .ToListAsync(); + var logs = await _dbContext.ChangeDb("log") + .Queryable() + .Where(x => x._ts <= threeDaysAgoStart) + .OrderBy(x => x._ts, OrderByType.Asc) + .ToListAsync(); - await _dbContext.ChangeDb("log").DeleteReallyAsync(logs); + await _dbContext.ChangeDb("log").DeleteReallyAsync(logs); + } + catch (Exception ex) + { + _logger.LogError(ex, "删除日志异常:{message}", ex.Message); + } + } }