您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

79 行
2.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace HBLConsole.Service
  9. {
  10. public class MessageLog
  11. {
  12. private volatile static MessageLog _Instance;
  13. public static MessageLog GetInstance => _Instance ?? (_Instance = new MessageLog());
  14. private MessageLog() { }
  15. private static readonly object _lock = new object();
  16. #region 普通消息日志
  17. /// <summary>
  18. /// 日志显示委托
  19. /// </summary>
  20. public Action<string, Color> InfoNotify { get; set; }
  21. /// <summary>
  22. /// 日志信息
  23. /// </summary>
  24. public string LogInfo { get; set; } = string.Empty;
  25. /// <summary>
  26. /// 普通日志输出
  27. /// </summary>
  28. /// <param name="info"></param>
  29. public void Show(string info, Color color = default(Color))
  30. {
  31. lock (_lock)
  32. {
  33. if (color.A == 0 && color.R == 0 && color.G == 0 && color.B == 0) color = Color.Aqua;
  34. Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
  35. LogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {LogInfo}";
  36. if (InfoNotify != null) InfoNotify(info, color);
  37. }
  38. }
  39. #endregion
  40. #region 异常消息日志
  41. /// <summary>
  42. /// 异常日志委托
  43. /// </summary>
  44. public Action<string, Color> ExInfoNotify { get; set; }
  45. /// <summary>
  46. /// 异常日志信息
  47. /// </summary>
  48. public string ExLogInfo { get; set; } = string.Empty;
  49. /// <summary>
  50. /// 异常日志输出
  51. /// </summary>
  52. /// <param name="info"></param>
  53. public void ShowEx(string info, Color color = default(Color))
  54. {
  55. lock (_lock)
  56. {
  57. color = Color.Red;
  58. Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
  59. ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}";
  60. if (ExInfoNotify != null) ExInfoNotify(info, color);
  61. }
  62. }
  63. #endregion
  64. }
  65. }