清理过期日志
public static void DelOverdueFiles(int days = 1) { string logDir = AppDomain.CurrentDomain.BaseDirectory + "/Logs/"; if (!Directory.Exists(logDir)) { return; } DirectoryInfo TheFolder = new DirectoryInfo(logDir); FileInfo[] files = TheFolder.GetFiles("*.txt", SearchOption.AllDirectories); foreach (FileInfo f2 in files.Where((FileInfo f) => (DateTime.Now - f.CreationTime).TotalDays > (double)days)) { try { File.Delete(f2.FullName); } catch (Exception) { } } }