12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.IO;
- using Aitex.Common.Util;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- namespace VirgoRT.HostWrapper
- {
- class FALogFileCleaner
- {
- PeriodicJob _threadDeleteLogs;
- public void Run()
- {
- //1天运行一次,删除一个月之前的FA log文件
- _threadDeleteLogs = new PeriodicJob(1000 * 60 * 60 * 24, OnDeleteLog, "DeleteFALog Thread", true);
- }
- bool OnDeleteLog()
- {
- try
- {
- string path = PathManager.GetLogDir();
- FileInfo[] fileInfos;
- DirectoryInfo curFolderInfo = new DirectoryInfo(path);
- fileInfos = curFolderInfo.GetFiles();
- foreach (FileInfo info in fileInfos)
- {
- if (info.Name.Contains("FabConnect") && info.Extension == ".log")
- {
- DateTime lastWriteTime = DateTime.Parse(info.LastWriteTime.ToShortDateString());
- DateTime intervalTime = DateTime.Now.AddMonths(-1);// DateTime.Parse(DateTime.Now.AddMonths(-1).ToShortDateString());
- if (lastWriteTime < intervalTime)
- {
- File.Delete(info.FullName);
- //LOG.Write(string.Format("【FA】自动删除FA log成功,logName:{0}", info.Name));
- }
- }
- }
- }
- catch (Exception ex)
- {
- LOG.Write(ex);
- }
- return true;
- }
- public void Stop()
- {
- _threadDeleteLogs.Stop();
- }
- }
- }
|