AuditInfo.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System;
  2. namespace Abp.Auditing
  3. {
  4. /// <summary>
  5. /// This informations are collected for an <see cref="AuditedAttribute"/> method.
  6. /// </summary>
  7. public class AuditInfo
  8. {
  9. /// <summary>
  10. /// TenantId.
  11. /// </summary>
  12. public int? TenantId { get; set; }
  13. /// <summary>
  14. /// UserId.
  15. /// </summary>
  16. public long? UserId { get; set; }
  17. /// <summary>
  18. /// ImpersonatorUserId.
  19. /// </summary>
  20. public long? ImpersonatorUserId { get; set; }
  21. /// <summary>
  22. /// ImpersonatorTenantId.
  23. /// </summary>
  24. public int? ImpersonatorTenantId { get; set; }
  25. /// <summary>
  26. /// Service (class/interface) name.
  27. /// </summary>
  28. public string ServiceName { get; set; }
  29. /// <summary>
  30. /// Executed method name.
  31. /// </summary>
  32. public string MethodName { get; set; }
  33. /// <summary>
  34. /// Calling parameters.
  35. /// </summary>
  36. public string Parameters { get; set; }
  37. /// <summary>
  38. /// Start time of the method execution.
  39. /// </summary>
  40. public DateTime ExecutionTime { get; set; }
  41. /// <summary>
  42. /// Total duration of the method call.
  43. /// </summary>
  44. public int ExecutionDuration { get; set; }
  45. /// <summary>
  46. /// IP address of the client.
  47. /// </summary>
  48. public string ClientIpAddress { get; set; }
  49. /// <summary>
  50. /// Name (generally computer name) of the client.
  51. /// </summary>
  52. public string ClientName { get; set; }
  53. /// <summary>
  54. /// Browser information if this method is called in a web request.
  55. /// </summary>
  56. public string BrowserInfo { get; set; }
  57. /// <summary>
  58. /// Optional custom data that can be filled and used.
  59. /// </summary>
  60. public string CustomData { get; set; }
  61. /// <summary>
  62. /// Exception object, if an exception occurred during execution of the method.
  63. /// </summary>
  64. public Exception Exception { get; set; }
  65. public override string ToString()
  66. {
  67. var loggedUserId = UserId.HasValue
  68. ? "user " + UserId.Value
  69. : "an anonymous user";
  70. var exceptionOrSuccessMessage = Exception != null
  71. ? "exception: " + Exception.Message
  72. : "succeed";
  73. return $"AUDIT LOG: {ServiceName}.{MethodName} is executed by {loggedUserId} in {ExecutionDuration} ms from {ClientIpAddress} IP address with {exceptionOrSuccessMessage}.";
  74. }
  75. }
  76. }