using Microsoft.Extensions.Logging; namespace ZB.MOM.WW.MxGateway.Tests.TestSupport; /// /// that records every entry's level and formatted message, /// so a test can assert that a path logs (or does not log) at a given level. /// /// The logger category type. public sealed class RecordingLogger : ILogger { private readonly object _syncRoot = new(); private readonly List<(LogLevel Level, string Message, Exception? Exception)> _entries = []; /// Gets a snapshot of the recorded entries, in order. public IReadOnlyList<(LogLevel Level, string Message, Exception? Exception)> Entries { get { lock (_syncRoot) { return _entries.ToArray(); } } } /// public IDisposable? BeginScope(TState state) where TState : notnull => null; /// public bool IsEnabled(LogLevel logLevel) => true; /// public void Log( LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { ArgumentNullException.ThrowIfNull(formatter); lock (_syncRoot) { _entries.Add((logLevel, formatter(state, exception), exception)); } } }