32 lines
792 B
C#
32 lines
792 B
C#
using Dlhis.Entity.Common;
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
namespace Dlhis.ScheduledTask.CommonJobs;
|
|
|
|
public class DelApiLogTaskJob
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
private readonly Logger<DelApiLogTaskJob> _logger;
|
|
|
|
public DelApiLogTaskJob(IDbContext dbContext, ILogger<DelApiLogTaskJob> logger)
|
|
{
|
|
_dbContext = dbContext;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task RunAsync()
|
|
{
|
|
try
|
|
{
|
|
DateTime before = DateTime.Now.Date.AddDays(-7);
|
|
await _dbContext.ChangeDb("log").Client.Deleteable<ApiLogEntity>().Where(x => x._ts <= before).ExecuteCommandAsync();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "删除日志异常:{message}", ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
|