FALogFileCleaner.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.IO;
  3. using Aitex.Common.Util;
  4. using Aitex.Core.RT.Log;
  5. using Aitex.Core.Util;
  6. namespace VirgoRT.HostWrapper
  7. {
  8. class FALogFileCleaner
  9. {
  10. PeriodicJob _threadDeleteLogs;
  11. public void Run()
  12. {
  13. //1天运行一次,删除一个月之前的FA log文件
  14. _threadDeleteLogs = new PeriodicJob(1000 * 60 * 60 * 24, OnDeleteLog, "DeleteFALog Thread", true);
  15. }
  16. bool OnDeleteLog()
  17. {
  18. try
  19. {
  20. string path = PathManager.GetLogDir();
  21. FileInfo[] fileInfos;
  22. DirectoryInfo curFolderInfo = new DirectoryInfo(path);
  23. fileInfos = curFolderInfo.GetFiles();
  24. foreach (FileInfo info in fileInfos)
  25. {
  26. if (info.Name.Contains("FabConnect") && info.Extension == ".log")
  27. {
  28. DateTime lastWriteTime = DateTime.Parse(info.LastWriteTime.ToShortDateString());
  29. DateTime intervalTime = DateTime.Now.AddMonths(-1);// DateTime.Parse(DateTime.Now.AddMonths(-1).ToShortDateString());
  30. if (lastWriteTime < intervalTime)
  31. {
  32. File.Delete(info.FullName);
  33. //LOG.Write(string.Format("【FA】自动删除FA log成功,logName:{0}", info.Name));
  34. }
  35. }
  36. }
  37. }
  38. catch (Exception ex)
  39. {
  40. LOG.Write(ex);
  41. }
  42. return true;
  43. }
  44. public void Stop()
  45. {
  46. _threadDeleteLogs.Stop();
  47. }
  48. }
  49. }