using log4net;
using System;
namespace GitConverter.Lib.Logging
{
///
/// Adapter that forwards library logging calls to a log4net instance.
///
///
/// - The adapter keeps the library free of direct log4net references except for the adapter itself.
/// - Constructor validates the provided to fail fast if misconfigured.
///
public sealed class Log4NetAdapter : IAppLogger
{
private readonly ILog _log;
///
/// Creates a new adapter that forwards calls to the specified .
///
/// A non-null log4net logger instance.
/// Thrown when is null.
public Log4NetAdapter(ILog log)
{
_log = log ?? throw new ArgumentNullException(nameof(log));
}
public void Debug(string message)
{
try { _log.Debug(message); }
catch { /* swallow to avoid logging causing application failures */ }
}
public void Info(string message)
{
try { _log.Info(message); }
catch { /* swallow to avoid logging causing application failures */ }
}
public void Warn(string message)
{
try { _log.Warn(message); }
catch { /* swallow to avoid logging causing application failures */ }
}
public void Error(string message, Exception ex = null)
{
try
{
if (ex != null) _log.Error(message, ex);
else _log.Error(message);
}
catch { /* swallow to avoid logging causing application failures */ }
}
}
}