| | | 1 | | using Elsa.Common; |
| | | 2 | | using Microsoft.Extensions.Logging; |
| | | 3 | | |
| | | 4 | | namespace Elsa.Alterations.Core.Models; |
| | | 5 | | |
| | | 6 | | |
| | | 7 | | /// <summary> |
| | | 8 | | /// Represents a log of alterations. |
| | | 9 | | /// </summary> |
| | | 10 | | public class AlterationLog |
| | | 11 | | { |
| | | 12 | | private readonly ISystemClock _systemClock; |
| | 0 | 13 | | private readonly List<AlterationLogEntry> _logEntries = new(); |
| | | 14 | | |
| | | 15 | | /// <summary> |
| | | 16 | | /// Initializes a new instance of the <see cref="AlterationLog"/> class. |
| | | 17 | | /// </summary> |
| | 0 | 18 | | public AlterationLog(ISystemClock systemClock) |
| | | 19 | | { |
| | 0 | 20 | | _systemClock = systemClock; |
| | 0 | 21 | | } |
| | | 22 | | |
| | | 23 | | /// <summary> |
| | | 24 | | /// Gets the log entries. |
| | | 25 | | /// </summary> |
| | 0 | 26 | | public IReadOnlyCollection<AlterationLogEntry> LogEntries => _logEntries.ToList().AsReadOnly(); |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Adds a log entry. |
| | | 30 | | /// </summary> |
| | | 31 | | /// <param name="message">The message.</param> |
| | | 32 | | /// <param name="logLevel">The log level.</param> |
| | | 33 | | /// <param name="eventName">The event that generated the log entry.</param> |
| | | 34 | | public void Add(string message, LogLevel logLevel = LogLevel.Information, string? eventName = null) |
| | | 35 | | { |
| | 0 | 36 | | var entry = new AlterationLogEntry(message, logLevel, _systemClock.UtcNow, eventName); |
| | | 37 | | |
| | 0 | 38 | | _logEntries.Add(entry); |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | /// <summary> |
| | | 42 | | /// Adds a set of log entries. |
| | | 43 | | /// </summary> |
| | | 44 | | /// <param name="entries"></param> |
| | 0 | 45 | | public void AddRange(IEnumerable<AlterationLogEntry> entries) => _logEntries.AddRange(entries); |
| | | 46 | | } |