Delete log files older than one month

pull/2164/head 5.10
2dust 2022-04-03 17:01:45 +08:00
parent bb828a4e06
commit 82924278b5
2 changed files with 32 additions and 2 deletions

View File

@ -35,6 +35,7 @@ namespace v2rayN
{
Logging.Setup();
Utils.SaveLog($"v2rayN start up | {Utils.GetVersion()} | {Utils.GetExePath()}");
Logging.ClearLogs();
//设置语言环境
string lang = Utils.RegReadValue(Global.MyRegPath, Global.MyRegKeyLanguage, "zh-Hans");

View File

@ -3,6 +3,9 @@ using log4net.Appender;
using log4net.Core;
using log4net.Layout;
using log4net.Repository.Hierarchy;
using System;
using System.IO;
using System.Threading.Tasks;
namespace v2rayN.Tool
{
@ -33,5 +36,31 @@ namespace v2rayN.Tool
hierarchy.Root.Level = Level.Info;
hierarchy.Configured = true;
}
public static void ClearLogs()
{
Task.Run(() =>
{
try
{
var now = DateTime.Now.AddMonths(-1);
var dir = Utils.GetPath(@"guiLogs\");
var files = Directory.GetFiles(dir, "*.txt");
foreach (var filePath in files)
{
var file = new FileInfo(filePath);
if (file.CreationTime < now)
{
try
{
file.Delete();
}
catch { }
}
}
}
catch { }
});
}
}
}