ActivityLog.cs 3.4 KB

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