Commit 8c3a2cf2 by ruyun.zhang@suvalue.com

Merge branch 'hotfix/删除历史日志'

parents 0b73f727 e9b25103
using FluentScheduler;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
namespace Performance.Api
{
/// <summary>
/// 删除历史日志
/// </summary>
public class ClearLoggerJob : IJob
{
private readonly ILogger<ClearLoggerJob> _logger;
public ClearLoggerJob(ILogger<ClearLoggerJob> logger)
{
_logger = logger;
}
public void Execute()
{
try
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs");
if (!Directory.Exists(path)) return;
var directories = Directory.GetDirectories(path);
foreach (var d in directories)
{
DirectoryInfo info = new DirectoryInfo(d);
if (info.LastWriteTime < DateTime.Now.AddMonths(-3))
Directory.Delete(d, true);
}
}
catch (Exception ex)
{
_logger.LogError("删除日志异常:{ex}", ex);
}
}
}
}
......@@ -19,6 +19,8 @@ public JobRegistry(IServiceProvider provider)
//Schedule<ExtractDataJob>().ToRunNow().AndEvery(1).Days().At(23, 0);
//Schedule<ExtractDataJob>().ToRunEvery(1).Days().At(23, 0);
Schedule(() => provider.GetService<ExtractGenerateJob>()).ToRunEvery(1).Days().At(23, 00);
//Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(60).Seconds();
Schedule(() => provider.GetService<ClearLoggerJob>()).ToRunNow().AndEvery(1).Days().At(3, 00);
}
}
}
......@@ -99,6 +99,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddTransient<ExtractGenerateJob>();
services.AddTransient<ExtractDataJob>();
services.AddTransient<ClearLoggerJob>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
......
......@@ -35,6 +35,6 @@ public class SaveGatherData
public string Source { get; set; }
public string Category { get; set; }
public string[] ColHeaders { get; set; }
public new string[][] Data { get; set; }
public string[][] Data { get; set; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment