proposal-system/api/tests/ProposalSystem.Tests/Helpers/CapturingLogger.cs

23 lines
578 B
C#
Raw Permalink Normal View History

using Microsoft.Extensions.Logging;
namespace ProposalSystem.Tests.Helpers;
internal sealed class CapturingLogger<T> : ILogger<T>
{
public List<string> Messages { get; } = [];
public IDisposable? BeginScope<TState>(TState state) where TState : notnull => null;
public bool IsEnabled(LogLevel logLevel) => true;
public void Log<TState>(
LogLevel logLevel,
EventId eventId,
TState state,
Exception? exception,
Func<TState, Exception?, string> formatter)
{
Messages.Add(formatter(state, exception));
}
}