fix 删除日志try
This commit is contained in:
@@ -7,25 +7,35 @@ namespace Dlhis.ScheduledTask.CommonJobs;
|
|||||||
public class DelApiLogTaskJob
|
public class DelApiLogTaskJob
|
||||||
{
|
{
|
||||||
private readonly IDbContext _dbContext;
|
private readonly IDbContext _dbContext;
|
||||||
|
private readonly Logger<DelApiLogTaskJob> _logger;
|
||||||
|
|
||||||
public DelApiLogTaskJob(IDbContext dbContext)
|
public DelApiLogTaskJob(IDbContext dbContext, Logger<DelApiLogTaskJob> logger)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task RunAsync()
|
public async Task RunAsync()
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.Now;
|
try
|
||||||
DateTime todayStart = now.Date;
|
{
|
||||||
DateTime threeDaysAgoStart = todayStart.AddDays(-3);
|
DateTime now = DateTime.Now;
|
||||||
|
DateTime todayStart = now.Date;
|
||||||
|
DateTime threeDaysAgoStart = todayStart.AddDays(-3);
|
||||||
|
|
||||||
var logs = await _dbContext.ChangeDb("log")
|
var logs = await _dbContext.ChangeDb("log")
|
||||||
.Queryable<ApiLogEntity>()
|
.Queryable<ApiLogEntity>()
|
||||||
.Where(x => x._ts<= threeDaysAgoStart)
|
.Where(x => x._ts <= threeDaysAgoStart)
|
||||||
.OrderBy(x =>x._ts,OrderByType.Asc)
|
.OrderBy(x => x._ts, OrderByType.Asc)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
await _dbContext.ChangeDb("log").DeleteReallyAsync(logs);
|
await _dbContext.ChangeDb("log").DeleteReallyAsync(logs);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "删除日志异常:{message}", ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user