Files
ThingsGateway/framework/admin/ThingsGateway.Admin.Application/Job/LogJob.cs

32 lines
1.6 KiB
C#
Raw Normal View History

2023-05-23 23:54:28 +08:00
#region copyright
//------------------------------------------------------------------------------
// 此代码版权声明为全文件覆盖,如有原作者特别声明,会在下方手动补充
// 此代码版权除特别声明外的代码归作者本人Diego所有
// 源代码使用协议遵循本仓库的开源协议及附加协议
2023-07-16 17:48:22 +08:00
// Gitee源代码仓库https://gitee.com/diego2098/ThingsGateway
2023-05-23 23:54:28 +08:00
// Github源代码仓库https://github.com/kimdiego2098/ThingsGateway
2023-07-16 17:48:22 +08:00
// 使用文档https://diego2098.gitee.io/thingsgateway-docs/
2023-05-23 23:54:28 +08:00
// QQ群605534569
//------------------------------------------------------------------------------
#endregion
using Furion.Schedule;
2023-03-04 18:41:11 +08:00
2023-08-07 15:09:53 +08:00
namespace ThingsGateway.Admin.Application;
2023-03-04 18:41:11 +08:00
/// <summary>
/// 清理日志作业任务
/// </summary>
2023-03-15 16:01:54 +08:00
[JobDetail("job_log", Description = "清理访问/操作日志", GroupName = "default", Concurrent = false)]
[Daily(TriggerId = "trigger_log", Description = "清理访问/操作日志", RunOnStart = true)]
2023-03-04 18:41:11 +08:00
public class LogJob : IJob
{
2023-04-02 16:59:46 +08:00
/// <inheritdoc/>
2023-03-04 18:41:11 +08:00
public async Task ExecuteAsync(JobExecutingContext context, CancellationToken stoppingToken)
{
var db = DbContext.Db.CopyNew();
2023-10-06 18:28:06 +08:00
var daysAgo = App.GetConfig<int?>("Logging:LogJob:DaysAgo") ?? 30;
2023-09-30 23:05:53 +08:00
await db.DeleteableWithAttr<SysVisitLog>().Where(u => u.CreateTime < DateTimeExtensions.CurrentDateTime.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除访问日志
await db.DeleteableWithAttr<SysOperateLog>().Where(u => u.CreateTime < DateTimeExtensions.CurrentDateTime.AddDays(-daysAgo)).ExecuteCommandAsync(stoppingToken); // 删除操作日志
2023-03-04 18:41:11 +08:00
}
}