using Microsoft.Extensions.Logging;
using GitConverter.Lib.Logging;
namespace GitConverter.TestsApp.Logging
{
///
/// Ensure MsLoggerAdapter swallows exceptions thrown by the underlying Microsoft ILogger.
///
public class MsLoggerAdapterSwallowTests
{
private class ThrowingLogger : ILogger
{
public IDisposable BeginScope(TState state) => null;
public bool IsEnabled(LogLevel logLevel) => true;
public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter)
{
throw new InvalidOperationException("logger boom");
}
}
[Fact]
public void Adapter_DoesNotThrow_WhenUnderlyingLoggerThrows()
{
var throwing = new ThrowingLogger();
var adapter = new MsLoggerAdapter(throwing);
// adapter methods should swallow underlying exceptions — no exception should propagate
adapter.Debug("d");
adapter.Info("i");
adapter.Warn("w");
var ex = Record.Exception(() => adapter.Error("e", new Exception("x")));
Assert.Null(ex);
}
}
}