using Microsoft.Extensions.Logging; namespace Bifrost.Web.Tests.Support; public sealed class CapturingLoggerProvider : ILoggerProvider { private readonly List _lines = []; public IReadOnlyList Lines { get { lock (_lines) { return _lines.ToArray(); } } } public ILogger CreateLogger(string categoryName) => new Capture(this); public void Dispose() { } private sealed class Capture(CapturingLoggerProvider owner) : ILogger { 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) { lock (owner._lines) { owner._lines.Add(formatter(state, exception) + (exception is null ? string.Empty : "\n" + exception)); } } } }