终端一体化运控平台
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.

MessageLog.cs 4.5 KiB

2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
2 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //using BPASmartClient.Peripheral;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using System.Linq;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Collections.Concurrent;
  10. namespace BPASmartClient.Message
  11. {
  12. public class MessageLog
  13. {
  14. private volatile static MessageLog _Instance;
  15. public static MessageLog GetInstance => _Instance ?? (_Instance = new MessageLog());
  16. private MessageLog() { }
  17. #region 普通消息日志
  18. /// <summary>
  19. /// 日志显示委托
  20. /// </summary>
  21. public Action<string> InfoNotify { get; set; }
  22. public Action<string> DebugLog { get; set; }
  23. public string DebugLogInfo { get; set; } = string.Empty;
  24. /// <summary>
  25. /// 日志信息
  26. /// </summary>
  27. public string LogInfo { get; set; } = string.Empty;
  28. /// <summary>
  29. /// 普通日志输出
  30. /// </summary>
  31. /// <param name="info"></param>
  32. public void Show(string info)
  33. {
  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);
  37. }
  38. public void ShowDebugLog(string info)
  39. {
  40. Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
  41. DebugLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DebugLogInfo}";
  42. DebugLog?.Invoke(info);
  43. }
  44. #endregion
  45. #region 异常消息日志
  46. /// <summary>
  47. /// 异常日志委托
  48. /// </summary>
  49. public Action<string> ExInfoNotify { get; set; }
  50. /// <summary>
  51. /// 异常日志信息
  52. /// </summary>
  53. public string ExLogInfo { get; set; } = string.Empty;
  54. /// <summary>
  55. /// 异常日志输出
  56. /// </summary>
  57. /// <param name="info"></param>
  58. public void ShowEx(string info)
  59. {
  60. Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
  61. ExLogInfo = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {ExLogInfo}";
  62. if (ExInfoNotify != null) ExInfoNotify(info);
  63. }
  64. #endregion
  65. #region 设备过程日志
  66. /// <summary>
  67. /// 设备过程日志委托
  68. /// </summary>
  69. public Action<string, string> DeviceProcessLogNotify { get; set; }
  70. /// <summary>
  71. /// 设备日志信息字典
  72. /// </summary>
  73. public ConcurrentDictionary<string, string> DPLogInfo = new ConcurrentDictionary<string, string>();
  74. /// <summary>
  75. /// 设备日志输出
  76. /// </summary>
  77. /// <param name="info"></param>
  78. public void DeviceProcessLogShow(string id, string info)
  79. {
  80. if (!DPLogInfo.ContainsKey(id))
  81. DPLogInfo.TryAdd(id, info);
  82. else
  83. DPLogInfo[id] = $"{DateTime.Now.ToString("HH:mm:ss")}:{info} \n\r {DPLogInfo[id]}";
  84. Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
  85. DeviceProcessLogNotify?.Invoke(id, info);
  86. }
  87. #endregion
  88. #region 设备告警日志
  89. /// <summary>
  90. /// 设备告警日志委托
  91. /// </summary>
  92. public Action<string, string> DeviceAlarmLogNotify { get; set; }
  93. public Action AlarmLogNotify { get; set; }
  94. /// <summary>
  95. /// 设备告警日志委托字典
  96. /// </summary>
  97. public ConcurrentDictionary<string, string> DPAlarmInfo = new ConcurrentDictionary<string, string>();
  98. /// <summary>
  99. /// 设备告警日志输出
  100. /// </summary>
  101. /// <param name="info"></param>
  102. public void AddDeviceAlarmLogShow(string id, string info)
  103. {
  104. DPAlarmInfo[info] = id;
  105. Debug.WriteLine($"{DateTime.Now.ToString("HH:mm:ss")}:{info}");
  106. if (DeviceAlarmLogNotify != null) DeviceAlarmLogNotify(id, info);
  107. if (AlarmLogNotify != null) AlarmLogNotify();
  108. }
  109. /// <summary>
  110. /// 设备告警日志输出
  111. /// </summary>
  112. /// <param name="info"></param>
  113. public void DeleteDeviceAlarmLogShow(string id, string info)
  114. {
  115. if (DPAlarmInfo.ContainsKey(id))
  116. {
  117. string mes = string.Empty;
  118. DPAlarmInfo.Remove(id, out mes);
  119. if (AlarmLogNotify != null) AlarmLogNotify();
  120. }
  121. }
  122. #endregion
  123. }
  124. }