using Microsoft.Extensions.Logging;
namespace Novelly.Api.Tests;
/// Records every entry logged through it, so tests can assert on what a service logged.
public record CapturedLogEntry(LogLevel Level, string Message, Exception? Exception);
///
/// A test double for that captures entries instead of
/// writing them anywhere, so tests can assert a service logged at the right level with the
/// right values without standing up a real sink.
///
public class CapturingLogger : ILogger
{
public List Entries { get; } = [];
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) =>
Entries.Add(new CapturedLogEntry(logLevel, formatter(state, exception), exception));
}