public static void Start(bool _useConsole, string directoryPath, int _intervalBetweenPurge) { // Create color pattern foreach (var color in Enum.GetValues(typeof(ConsoleColor))) { colorPattern += $"({color}" + "{)" + "|"; } colorPattern += "(})"; // Save variable and instantiate logging intervalBetweenPurge = _intervalBetweenPurge; useConsole = _useConsole; if (IOSupport.IsDirectoryWriteable(directoryPath)) { logEntries = new ConcurrentQueue <LogEntry>(); Started = true; Write($"Application {Process.GetCurrentProcess().ProcessName} started (logging enabled)"); task = new CancellableTask((token) => { while (!((CancellationToken)token).IsCancellationRequested) { PurgeQueue(directoryPath); if (applicationExiting) { Write($"Application {Process.GetCurrentProcess().ProcessName} terminated", LogEntry.SeverityType.High); PurgeQueue(directoryPath); return; } task.SleepOrExit(intervalBetweenPurge); } }); task.Start(); } else { Write($"Application {Process.GetCurrentProcess().ProcessName} started (logging disabled)"); } }
public void Sleep(int cautiousWaitTime = 0) { cancellableTask.SleepOrExit(cautiousWaitTime > 0? cautiousWaitTime : MinimalWaitBetweenAction); }