using Microsoft.Extensions.Logging;
using ZB.MOM.WW.OtOpcUa.Driver.TwinCAT;
namespace ZB.MOM.WW.OtOpcUa.Driver.TwinCAT.Tests;
/// Collects the driver's Warning-level messages (thread-safe) for once-per-X assertions.
internal sealed class TwinCATCapturingLogger : ILogger
{
private readonly List _warnings = [];
/// Gets a snapshot of the formatted Warning messages logged so far.
public IReadOnlyList Warnings { get { lock (_warnings) return [.. _warnings]; } }
///
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)
{
if (logLevel == LogLevel.Warning) lock (_warnings) _warnings.Add(formatter(state, exception));
}
}