using Microsoft.Extensions.Logging;
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Tests.Runtime;
/// Logger that records every formatted message (and exception text) for leak assertions.
internal sealed class CapturingLogger : ILogger
{
/// Gets the formatted entries, each including the exception's ToString when present.
public List<(LogLevel Level, string Text)> Entries { get; } = [];
/// Gets every entry's text joined, for a single contains-check.
public string AllText => string.Join("\n", Entries.Select(e => e.Text));
///
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)
{
// Include the structured state values too — a password passed as a template argument would
// reach a structured sink even if the template text omitted it.
var values = state is IEnumerable> kvs
? string.Join(";", kvs.Select(kv => $"{kv.Key}={kv.Value}"))
: string.Empty;
Entries.Add((logLevel, $"{formatter(state, exception)} | {values} | {exception}"));
}
}