using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; namespace StellaOps.Feedser.Merge.Tests; internal sealed class TestLogger : ILogger { private static readonly IDisposable NoopScope = new DisposableScope(); public List Entries { get; } = new(); public IDisposable BeginScope(TState state) where TState : notnull => NoopScope; public bool IsEnabled(LogLevel logLevel) => true; public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { if (formatter is null) { throw new ArgumentNullException(nameof(formatter)); } IReadOnlyList>? structuredState = null; if (state is IReadOnlyList> list) { structuredState = list.ToArray(); } else if (state is IEnumerable> enumerable) { structuredState = enumerable.ToArray(); } Entries.Add(new LogEntry(logLevel, eventId, formatter(state, exception), structuredState)); } internal sealed record LogEntry( LogLevel Level, EventId EventId, string Message, IReadOnlyList>? StructuredState); private sealed class DisposableScope : IDisposable { public void Dispose() { } } }