You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace JwKdsV.Core
|
|
{
|
|
public class AsyncWorker
|
|
{
|
|
protected static NLog.Logger logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
/// <summary>
|
|
/// 删除历史日志文件
|
|
/// </summary>
|
|
public static void DeleteHistoryLogFile()
|
|
{
|
|
Task.Factory.StartNew(new Action(() =>
|
|
{
|
|
try
|
|
{
|
|
//删除60天之前的日志文件
|
|
var day60Str = DateTime.Now.AddDays(-60).ToString("yyyyMMdd");
|
|
var adDirPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"logs");
|
|
if (Directory.Exists(adDirPath))
|
|
{
|
|
//路径存在,查找文件
|
|
DirectoryInfo TheFolder = new DirectoryInfo(adDirPath);
|
|
var files = TheFolder.GetFiles();
|
|
foreach (FileInfo NextFile in files)
|
|
{
|
|
if (NextFile.Name.CompareTo(day60Str) < 0)
|
|
{
|
|
NextFile.Delete();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
logger.Error(ex, "删除历史日志文件异常");
|
|
}
|
|
}));
|
|
}
|
|
}
|
|
}
|