You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.4 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. namespace Apewer.Web
  4. {
  5. /// <summary></summary>
  6. public static class CronLog
  7. {
  8. private static object Locker = new object();
  9. /// <summary>合并 Log 内容。</summary>
  10. public static string Merge(params object[] content)
  11. {
  12. var text = TextUtility.Join(" | ", content) ?? "";
  13. text = "Cron | " + text;
  14. return text;
  15. }
  16. /// <summary>合并 Log 内容。</summary>
  17. public static string Merge(Exception exception)
  18. {
  19. try { return Merge("Exception", exception.GetType().FullName, exception.Message); }
  20. catch { return Merge("Exception", "无法记录日志的异常。"); }
  21. }
  22. /// <summary>调用 Log 处理程序。</summary>
  23. public static void Invoke(Action<string> action, params object[] content)
  24. {
  25. RuntimeUtility.InBackground(() =>
  26. {
  27. var text = Merge(content);
  28. lock (Locker)
  29. {
  30. try
  31. {
  32. if (action == null) Console(text);
  33. else action(text);
  34. }
  35. catch { }
  36. }
  37. });
  38. }
  39. /// <summary>向控制台写入文本的 Log 处理程序。</summary>
  40. public static void Console(string text) => Logger.Web.Text("Cron", text);
  41. }
  42. }