1
huanghongfeng
2025-06-06 f5b8c1ae89286dada20ea433ffac84f4c9e72a29
代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_Tasks/LogJob.cs
@@ -37,8 +37,9 @@
                        while (true)
                        {
                            WriteLog.GetLog("LogJob").Write($"鏃ュ織璁板綍锛歿DateTime.Now}", "LogJob");
                            Run(5);
                            Thread.Sleep(1000 * 60);
                            Run(10);
                            Run2(10);
                            Thread.Sleep(1000 * 10);
                        }
                    }
                    catch { }
@@ -85,6 +86,40 @@
                }
            }
        }
        private static void Run2(int saveDays)
        {
            var logPath = System.Environment.CurrentDirectory + "/txt";
            if (Directory.Exists(logPath))
            {
                var nowTime = DateTime.Now;
                var dayDir = Directory.GetDirectories(logPath, "20*", System.IO.SearchOption.AllDirectories);
                foreach (var dirpath in dayDir)
                {
                    //鏂囦欢澶瑰悕
                    var dirName = Path.GetFileName(dirpath).Replace("_", "-");
                    DateTime targetDate = DateTime.ParseExact(dirName, "yyyyMMdd", null);
                    if ((nowTime - targetDate).TotalDays >= saveDays)
                    {
                        //鍒犻櫎鏂囦欢鍜屾枃浠跺す
                        try
                        {
                            var flies = Directory.GetFiles(dirpath);
                            foreach (var item in flies)
                            {
                                File.Delete(item);
                            }
                            Directory.Delete(dirpath);
                        }
                        catch { }
                    }
                }
            }
        }
    }