LogHelper.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. namespace DefaultEdit.Log4xml
  3. {
  4. public class LogHelper
  5. {
  6. public delegate void LogChangHandler(Log log);
  7. public static LogChangHandler logChangHandler;
  8. // #region 执行日志
  9. private static readonly log4net.ILog infologger = log4net.LogManager.GetLogger("LogInfo");
  10. /// <summary>
  11. /// 普通日志
  12. /// </summary>
  13. /// <param name="message">日志内容</param>
  14. public static void Info(string message)
  15. {
  16. // 可以改成type typeof(类)
  17. if ( infologger.IsInfoEnabled )
  18. {
  19. infologger.Info(message);
  20. logChangHandler?.Invoke(new Log() { Time = DateTime.Now.ToString("yyyy-MM-dd:HH:mm:ss"), Msg = message });
  21. }
  22. }
  23. private static readonly log4net.ILog debuglogger = log4net.LogManager.GetLogger("DebugInfo");
  24. public static void Debuginfo(string message)
  25. {
  26. // 可以改成type typeof(类)
  27. if ( debuglogger.IsInfoEnabled )
  28. {
  29. debuglogger.Info(message);
  30. // logChangHandler?.Invoke(new Log() { Time = DateTime.Now.ToString("yyyy-MM-dd:HH:mm:ss"), Msg = message });
  31. }
  32. }
  33. private static readonly log4net.ILog infologgermes = log4net.LogManager.GetLogger("LogMes");
  34. /// <summary>
  35. /// 普通日志
  36. /// </summary>
  37. /// <param name="message">日志内容</param>
  38. public static void MesInfo(string message)
  39. {
  40. // 可以改成type typeof(类)
  41. if ( infologgermes.IsInfoEnabled )
  42. {
  43. infologgermes.Info(message);
  44. //logChangHandler?.Invoke(new Log() { Time = DateTime.Now.ToString("yyyy-MM-dd:HH:mm:ss"), Msg = message });
  45. }
  46. }
  47. private static log4net.ILog alarmlog4net =log4net.LogManager.GetLogger("AlarmLogInfo");
  48. /// <summary>
  49. /// 警告日志
  50. /// </summary>
  51. /// <param name="message">警告日志</param>
  52. public static void Warn(string message)
  53. {
  54. if ( alarmlog4net.IsWarnEnabled )
  55. {
  56. alarmlog4net.Warn(message);
  57. }
  58. }
  59. private static log4net.ILog Errlog4net =log4net.LogManager.GetLogger("ErrLogInfo");
  60. /// <summary>
  61. /// 错误日志
  62. /// </summary>
  63. /// <param name="message">错误日志</param>
  64. public static void Error(string message)
  65. {
  66. if ( Errlog4net.IsInfoEnabled )
  67. {
  68. Errlog4net.Error(message);
  69. }
  70. }
  71. }
  72. public class Log
  73. {
  74. private string time;
  75. private string msg;
  76. public string Time { get => time; set => time = value; }
  77. public string Msg { get { return time + " " + msg; } set => msg = value; }
  78. }
  79. }