LogHelper.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. namespace CommonUtils.Log4
  9. {
  10. public class LogHelper
  11. {
  12. public delegate void ServerLogChangHandler(Log log);
  13. public delegate void PrinterLogChangHandler(Log log);
  14. public delegate void AgvLogChangHandler(Log log);
  15. // #region 执行日志
  16. private static readonly log4net.ILog infologger = log4net.LogManager.GetLogger("LogInfo");
  17. /// <summary>
  18. /// 普通日志
  19. /// </summary>
  20. /// <param name="message">日志内容</param>
  21. public static void Info(string message)
  22. {
  23. // 可以改成type typeof(类)
  24. if ( infologger.IsInfoEnabled)
  25. {
  26. infologger.Info(message);
  27. }
  28. }
  29. private static log4net.ILog alarmlog4net =log4net.LogManager.GetLogger("AlarmLogInfo");
  30. /// <summary>
  31. /// 警告日志
  32. /// </summary>
  33. /// <param name="message">警告日志</param>
  34. public static void Warn(string message)
  35. {
  36. if ( alarmlog4net.IsWarnEnabled )
  37. {
  38. alarmlog4net.Warn(message);
  39. }
  40. }
  41. private static log4net.ILog Errlog4net =log4net.LogManager.GetLogger("ErrLogInfo");
  42. /// <summary>
  43. /// 错误日志
  44. /// </summary>
  45. /// <param name="message">错误日志</param>
  46. public static void Error(string message)
  47. {
  48. if ( Errlog4net.IsInfoEnabled )
  49. {
  50. Errlog4net.Error(message);
  51. }
  52. }
  53. }
  54. public class Log
  55. {
  56. private string time;
  57. private string msg;
  58. public string Time { get => time; set => time = value; }
  59. public string Msg { get {return time +" "+ msg; } set => msg = value; }
  60. }
  61. }