LogHelper.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using log4net;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. namespace LocalhostMES.Core
  9. {
  10. public static class LogHelper
  11. {
  12. public static readonly ILog loginfo = LogManager.GetLogger("loginfo");
  13. public static readonly ILog logerror = LogManager.GetLogger("logerror");
  14. public static readonly ILog logdebug = LogManager.GetLogger("logdebug");
  15. public static readonly ILog logwarn = LogManager.GetLogger("logwarn");
  16. public static readonly ILog logfatal = LogManager.GetLogger("logfatal");
  17. public static readonly ILog logDynamic = LogManager.GetLogger("logDynamic");
  18. public delegate void LogChangHandler(string msg);
  19. public static LogChangHandler logChangHandler;
  20. public static void WriteLogInfo(string info)
  21. {
  22. if ( loginfo.IsInfoEnabled )
  23. {
  24. loginfo.Info(info);
  25. logChangHandler?.Invoke(info);
  26. }
  27. }
  28. public static void WriteLogDebug(string info)
  29. {
  30. if ( logdebug.IsDebugEnabled )
  31. {
  32. logdebug.Debug(info);
  33. }
  34. }
  35. public static void WriteLogWarn(string info)
  36. {
  37. if ( logwarn.IsWarnEnabled )
  38. {
  39. logwarn.Warn(info);
  40. }
  41. }
  42. public static void WriteLogError(string info, Exception se)
  43. {
  44. if ( logerror.IsErrorEnabled )
  45. {
  46. logerror.Error(info, se);
  47. }
  48. }
  49. public static void WriteLogFatal(string info, Exception se)
  50. {
  51. if ( logfatal.IsFatalEnabled )
  52. {
  53. logfatal.Fatal(info, se);
  54. }
  55. }
  56. public static void WriteOther(string info)
  57. {
  58. if ( logDynamic.IsInfoEnabled )
  59. {
  60. logDynamic.Info(info);
  61. }
  62. }
  63. }
  64. }