ActivityLog.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using System;
  2. using System.ComponentModel.DataAnnotations;
  3. using System.ComponentModel.DataAnnotations.Schema;
  4. using Jellyfin.Data.Interfaces;
  5. using Microsoft.Extensions.Logging;
  6. namespace Jellyfin.Data.Entities
  7. {
  8. /// <summary>
  9. /// An entity referencing an activity log entry.
  10. /// </summary>
  11. public class ActivityLog : IHasConcurrencyToken
  12. {
  13. /// <summary>
  14. /// Initializes a new instance of the <see cref="ActivityLog"/> class.
  15. /// Public constructor with required data.
  16. /// </summary>
  17. /// <param name="name">The name.</param>
  18. /// <param name="type">The type.</param>
  19. /// <param name="userId">The user id.</param>
  20. /// <param name="logLevel">The log level.</param>
  21. public ActivityLog(string name, string type, Guid userId, LogLevel logLevel = LogLevel.Information)
  22. {
  23. if (string.IsNullOrEmpty(name))
  24. {
  25. throw new ArgumentNullException(nameof(name));
  26. }
  27. if (string.IsNullOrEmpty(type))
  28. {
  29. throw new ArgumentNullException(nameof(type));
  30. }
  31. Name = name;
  32. Type = type;
  33. UserId = userId;
  34. DateCreated = DateTime.UtcNow;
  35. LogSeverity = logLevel;
  36. }
  37. /// <summary>
  38. /// Initializes a new instance of the <see cref="ActivityLog"/> class.
  39. /// Default constructor. Protected due to required properties, but present because EF needs it.
  40. /// </summary>
  41. protected ActivityLog()
  42. {
  43. }
  44. /// <summary>
  45. /// Gets or sets the identity of this instance.
  46. /// This is the key in the backing database.
  47. /// </summary>
  48. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  49. public int Id { get; protected set; }
  50. /// <summary>
  51. /// Gets or sets the name.
  52. /// </summary>
  53. /// <remarks>
  54. /// Required, Max length = 512.
  55. /// </remarks>
  56. [Required]
  57. [MaxLength(512)]
  58. [StringLength(512)]
  59. public string Name { get; set; }
  60. /// <summary>
  61. /// Gets or sets the overview.
  62. /// </summary>
  63. /// <remarks>
  64. /// Max length = 512.
  65. /// </remarks>
  66. [MaxLength(512)]
  67. [StringLength(512)]
  68. public string Overview { get; set; }
  69. /// <summary>
  70. /// Gets or sets the short overview.
  71. /// </summary>
  72. /// <remarks>
  73. /// Max length = 512.
  74. /// </remarks>
  75. [MaxLength(512)]
  76. [StringLength(512)]
  77. public string ShortOverview { get; set; }
  78. /// <summary>
  79. /// Gets or sets the type.
  80. /// </summary>
  81. /// <remarks>
  82. /// Required, Max length = 256.
  83. /// </remarks>
  84. [Required]
  85. [MaxLength(256)]
  86. [StringLength(256)]
  87. public string Type { get; set; }
  88. /// <summary>
  89. /// Gets or sets the user id.
  90. /// </summary>
  91. /// <remarks>
  92. /// Required.
  93. /// </remarks>
  94. public Guid UserId { get; set; }
  95. /// <summary>
  96. /// Gets or sets the item id.
  97. /// </summary>
  98. /// <remarks>
  99. /// Max length = 256.
  100. /// </remarks>
  101. [MaxLength(256)]
  102. [StringLength(256)]
  103. public string ItemId { get; set; }
  104. /// <summary>
  105. /// Gets or sets the date created. This should be in UTC.
  106. /// </summary>
  107. /// <remarks>
  108. /// Required.
  109. /// </remarks>
  110. public DateTime DateCreated { get; set; }
  111. /// <summary>
  112. /// Gets or sets the log severity. Default is <see cref="LogLevel.Trace"/>.
  113. /// </summary>
  114. /// <remarks>
  115. /// Required.
  116. /// </remarks>
  117. public LogLevel LogSeverity { get; set; }
  118. /// <inheritdoc />
  119. [ConcurrencyCheck]
  120. public uint RowVersion { get; set; }
  121. /// <inheritdoc />
  122. public void OnSavingChanges()
  123. {
  124. RowVersion++;
  125. }
  126. }
  127. }