// -------------------------------------------------------------------------------------------------------------------------- public static void LoggedTask(Action task, LoggedTaskOptions options) { var sw = Stopwatch.StartNew(); Gopher.Log(options.StartMessage); try { task.Invoke(); } catch (Exception ex) { Gopher.Log(options.ErrorMessage, Gopher.LOG_CATEGORY_ERROR); Gopher.Log(ex.Message, Gopher.LOG_CATEGORY_ERROR); options.ErrorHandler?.Invoke(ex); if (options.RethrowExceptions) { throw; } return; } Gopher.Log(options.CompleteMessage + (options.ReportTime ? $"\t({sw.Elapsed.TotalSeconds:f3}s)" : "")); const bool INCLUE_BREAK = true; if (INCLUE_BREAK) { Gopher.Log(""); } }
// -------------------------------------------------------------------------------------------------------------------------- public static void LoggedTask(string startMsg, string completeMsg, string errMsg, Action task, Action <Exception> errHandler = null, bool rethrow = false) { LoggedTaskOptions ops = new LoggedTaskOptions() { StartMessage = startMsg, CompleteMessage = completeMsg, ErrorMessage = errMsg, ErrorHandler = errHandler, RethrowExceptions = rethrow, }; LoggedTask(task, ops); }