internal void DoMaintenanceNow() { lastFileMaintenanceTime = DateTimeEx.Now; foreach (var kvp in directoryNamesAndDays) { int days = kvp.Value; if (days < 0) { continue; } if (Verbose) { SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, kvp.Key + ": Deleting files older than " + days + " days."); } bool removeDirectory = false; if (directoryNamesAndRemoveDirectory.ContainsKey(kvp.Key)) { removeDirectory = directoryNamesAndRemoveDirectory[kvp.Key]; } DeleteOldFiles(kvp.Key, days, removeDirectory); } if (Verbose) { SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, "Maintenance complete. Next maintenance time: " + DateTimeEx.ToStdDateTimeFormat(lastFileMaintenanceTime.AddMinutes(minutesBetweenMaintenance))); } }
public static void RecordException(string s, bool assert) { if (SameExceptionHappenedLessThanMillisecondAgo(s)) { return; } SimpleFileWriter.WriteLineToEventFile(DirectoryName.EventLog, s); Debug.Assert(assert, s); }
// -1: do not delete files, 0: delete files immediately public void AddDirectory(string directoryName, int days, bool removeDirectoryIfEmpty = false) { if (Verbose) { SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, String.Format("Adding directory {0} under automatic maintenance. ", directoryName)); SimpleFileWriter.WriteLineToEventFile(DirectoryName.Diag, String.Format("Files older than {0} days will be deleted automatically", days.ToIcString())); } directoryNamesAndDays[directoryName] = days; directoryNamesAndRemoveDirectory[directoryName] = removeDirectoryIfEmpty; }
private static void ProcessException(string s) { SimpleFileWriter.WriteStackToDiagnosticsLog(s); SimpleFileWriter.WriteLineToEventFile(DirectoryName.EventLog, s); #if DEBUG // Debugger.Break(); string s1 = string.Format(CultureInfo.InvariantCulture, "{0}\t{1}\t{2}\r\n", DateTimeEx.NowToString, s, SimpleFileWriter.GetStack); Debug.Assert(false, s + Environment.NewLine + s1); #endif }