ExtLogImpl.cs 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using log4net.Core;
  6. namespace log4net.Ext
  7. {
  8. public class ExtLogImpl : LogImpl, IExtLog
  9. {
  10. /// <summary>
  11. /// The fully qualified name of this declaring type not the type of any subclass.
  12. /// </summary>
  13. private readonly static Type ThisDeclaringType = typeof(ExtLogImpl);
  14. public ExtLogImpl(ILogger logger)
  15. : base(logger)
  16. {
  17. }
  18. #region IExtLog 成员
  19. public void Info(string clientIP, string clientUser, string requestUri, string action, object message)
  20. {
  21. Info(clientIP, clientUser, requestUri, action, message, null);
  22. }
  23. public void Info(string clientIP, string clientUser, string requestUri, string action, object message, Exception t)
  24. {
  25. if (this.IsInfoEnabled)
  26. {
  27. LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, Logger.Repository, Logger.Name, Level.Info, message, t);
  28. loggingEvent.Properties["ClientIP"] = clientIP;
  29. loggingEvent.Properties["ClientUser"] = clientUser;
  30. loggingEvent.Properties["RequestUrl"] = requestUri;
  31. loggingEvent.Properties["Action"] = action;
  32. Logger.Log(loggingEvent);
  33. }
  34. }
  35. public void Warn(string clientIP, string clientUser, string requestUri, string action, object message)
  36. {
  37. Warn(clientIP, clientUser, requestUri, action, message, null);
  38. }
  39. public void Warn(string clientIP, string clientUser, string requestUri, string action, object message, Exception t)
  40. {
  41. if (this.IsWarnEnabled)
  42. {
  43. LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, Logger.Repository, Logger.Name, Level.Warn, message, t);
  44. loggingEvent.Properties["ClientIP"] = clientIP;
  45. loggingEvent.Properties["ClientUser"] = clientUser;
  46. loggingEvent.Properties["RequestUrl"] = requestUri;
  47. loggingEvent.Properties["Action"] = action;
  48. Logger.Log(loggingEvent);
  49. }
  50. }
  51. public void Error(string clientIP, string clientUser, string requestUri, string action, object message)
  52. {
  53. Error(clientIP, clientUser, requestUri, action, message, null);
  54. }
  55. public void Error(string clientIP, string clientUser, string requestUri, string action, object message, Exception t)
  56. {
  57. if (this.IsErrorEnabled)
  58. {
  59. LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, Logger.Repository, Logger.Name, Level.Error, message, t);
  60. loggingEvent.Properties["ClientIP"] = clientIP;
  61. loggingEvent.Properties["ClientUser"] = clientUser;
  62. loggingEvent.Properties["RequestUrl"] = requestUri;
  63. loggingEvent.Properties["Action"] = action;
  64. Logger.Log(loggingEvent);
  65. }
  66. }
  67. public void Fatal(string clientIP, string clientUser, string requestUri, string action, object message)
  68. {
  69. Fatal(clientIP, clientUser, requestUri, action, message, null);
  70. }
  71. public void Fatal(string clientIP, string clientUser, string requestUri, string action, object message, Exception t)
  72. {
  73. if (this.IsFatalEnabled)
  74. {
  75. LoggingEvent loggingEvent = new LoggingEvent(ThisDeclaringType, Logger.Repository, Logger.Name, Level.Fatal, message, t);
  76. loggingEvent.Properties["ClientIP"] = clientIP;
  77. loggingEvent.Properties["ClientUser"] = clientUser;
  78. loggingEvent.Properties["RequestUrl"] = requestUri;
  79. loggingEvent.Properties["Action"] = action;
  80. Logger.Log(loggingEvent);
  81. }
  82. }
  83. #endregion
  84. }
  85. }