Path: redb-route/tests/redb.Route.Tests.Kafka/CapturingLoggerProvider.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.Kafka/CapturingLoggerProvider.cs
----
using System.Collections.Concurrent;
using Microsoft.Extensions.Logging;
namespace redb.Route.Tests.Kafka;
/// Test-only logger provider that keeps every entry in memory, for assertions on what the connector says.
internal sealed class CapturingLoggerProvider : ILoggerProvider
{
public ConcurrentQueue Entries { get; } = new();
public ILogger CreateLogger(string categoryName) => new Logger(this);
public void Dispose() { }
internal sealed record LogEntry(LogLevel Level, string Message);
private sealed class Logger(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) =>
owner.Entries.Enqueue(new LogEntry(logLevel, formatter(state, exception)));
}
}