using System; using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.Logging; namespace Jellyfin.Server.Tests.HighAvailability; /// /// An that keeps every formatted entry so tests can assert on the startup /// signals operators rely on. /// /// The category type. internal sealed class RecordingLogger : ILogger { private readonly List<(LogLevel Level, string Message, Exception? Exception)> _entries = new(); public IReadOnlyList<(LogLevel Level, string Message, Exception? Exception)> Entries => _entries; public IDisposable BeginScope(TState state) where TState : notnull => NoopScope.Instance; public bool IsEnabled(LogLevel logLevel) => true; public void Log(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func formatter) { ArgumentNullException.ThrowIfNull(formatter); _entries.Add((logLevel, formatter(state, exception), exception)); } public bool HasEntry(LogLevel level, string substring) => _entries.Any(entry => entry.Level == level && entry.Message.Contains(substring, StringComparison.Ordinal)); private sealed class NoopScope : IDisposable { public static readonly NoopScope Instance = new(); public void Dispose() { } } }