ActivityLog.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. public ActivityLog(string name, string type, Guid userId)
  21. {
  22. if (string.IsNullOrEmpty(name))
  23. {
  24. throw new ArgumentNullException(nameof(name));
  25. }
  26. if (string.IsNullOrEmpty(type))
  27. {
  28. throw new ArgumentNullException(nameof(type));
  29. }
  30. Name = name;
  31. Type = type;
  32. UserId = userId;
  33. DateCreated = DateTime.UtcNow;
  34. LogSeverity = LogLevel.Information;
  35. }
  36. /// <summary>
  37. /// Gets or sets the identity of this instance.
  38. /// This is the key in the backing database.
  39. /// </summary>
  40. [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
  41. public int Id { get; protected set; }
  42. /// <summary>
  43. /// Gets or sets the name.
  44. /// </summary>
  45. /// <remarks>
  46. /// Required, Max length = 512.
  47. /// </remarks>
  48. [MaxLength(512)]
  49. [StringLength(512)]
  50. public string Name { get; set; }
  51. /// <summary>
  52. /// Gets or sets the overview.
  53. /// </summary>
  54. /// <remarks>
  55. /// Max length = 512.
  56. /// </remarks>
  57. [MaxLength(512)]
  58. [StringLength(512)]
  59. public string? Overview { get; set; }
  60. /// <summary>
  61. /// Gets or sets the short overview.
  62. /// </summary>
  63. /// <remarks>
  64. /// Max length = 512.
  65. /// </remarks>
  66. [MaxLength(512)]
  67. [StringLength(512)]
  68. public string? ShortOverview { get; set; }
  69. /// <summary>
  70. /// Gets or sets the type.
  71. /// </summary>
  72. /// <remarks>
  73. /// Required, Max length = 256.
  74. /// </remarks>
  75. [MaxLength(256)]
  76. [StringLength(256)]
  77. public string Type { get; set; }
  78. /// <summary>
  79. /// Gets or sets the user id.
  80. /// </summary>
  81. /// <remarks>
  82. /// Required.
  83. /// </remarks>
  84. public Guid UserId { get; set; }
  85. /// <summary>
  86. /// Gets or sets the item id.
  87. /// </summary>
  88. /// <remarks>
  89. /// Max length = 256.
  90. /// </remarks>
  91. [MaxLength(256)]
  92. [StringLength(256)]
  93. public string? ItemId { get; set; }
  94. /// <summary>
  95. /// Gets or sets the date created. This should be in UTC.
  96. /// </summary>
  97. /// <remarks>
  98. /// Required.
  99. /// </remarks>
  100. public DateTime DateCreated { get; set; }
  101. /// <summary>
  102. /// Gets or sets the log severity. Default is <see cref="LogLevel.Trace"/>.
  103. /// </summary>
  104. /// <remarks>
  105. /// Required.
  106. /// </remarks>
  107. public LogLevel LogSeverity { get; set; }
  108. /// <inheritdoc />
  109. [ConcurrencyCheck]
  110. public uint RowVersion { get; set; }
  111. /// <inheritdoc />
  112. public void OnSavingChanges()
  113. {
  114. RowVersion++;
  115. }
  116. }
  117. }