using System; using System.Collections.Generic; namespace Apewer.Web { /// public static class CronLog { private static object Locker = new object(); /// 合并 Log 内容。 public static string Merge(params object[] content) { var text = TextUtility.Join(" | ", content) ?? ""; text = "Cron | " + text; return text; } /// 合并 Log 内容。 public static string Merge(Exception exception) { try { return Merge("Exception", exception.GetType().FullName, exception.Message); } catch { return Merge("Exception", "无法记录日志的异常。"); } } /// 调用 Log 处理程序。 public static void Invoke(Action action, params object[] content) { KernelUtility.InBackground(() => { var text = Merge(content); lock (Locker) { try { if (action == null) Console(text); else action(text); } catch { } } }); } /// 向控制台写入文本的 Log 处理程序。 public static void Console(string text) { if (string.IsNullOrEmpty(text)) return; var withTime = TextUtility.Merge(DateTime.Now.ToLucid(), " ", text); System.Console.WriteLine(withTime); } } }