123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.IO;
- using Aitex.Core.RT.Log;
- using Aitex.Core.Util;
- namespace Aitex.RT.FactoryAutomation
- {
- 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 = string.Format(@"{0}", "Logs");
- 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();
- }
- }
- }
|