J'ai finalement créé deux classes:
public class CommonLoggingNLogAdapter : ILoggerFactoryAdapter
{
public ILog GetLogger(Type type)
{
return new NLogAdapter(type);
}
public ILog GetLogger(string key)
{
return new NLogAdapter(key);
}
}
et
public class NLogAdapter : ILog
{
private Logger log;
public bool IsTraceEnabled { get { return log.IsTraceEnabled; } }
public bool IsDebugEnabled { get { return log.IsDebugEnabled; } }
public bool IsErrorEnabled { get { return log.IsErrorEnabled; } }
public bool IsFatalEnabled { get { return log.IsFatalEnabled; } }
public bool IsInfoEnabled { get { return log.IsInfoEnabled; } }
public bool IsWarnEnabled { get { return log.IsWarnEnabled; } }
public IVariablesContext GlobalVariablesContext => throw new NotImplementedException();
public IVariablesContext ThreadVariablesContext => throw new NotImplementedException();
public INestedVariablesContext NestedThreadVariablesContext => throw new NotImplementedException();
public NLogAdapter(Type type)
{
log = NLog.LogManager.GetLogger(type.ToString());
}
public NLogAdapter(string key)
{
log = NLog.LogManager.GetLogger(key);
}
public void Debug(object message)
{
log.Debug(message);
}
public void Debug(object message, Exception exception)
{
log.Debug(exception, message.ToString());
}
public void Debug(Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Debug(Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void Debug(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Debug(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void DebugFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void DebugFormat(string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void DebugFormat(IFormatProvider formatProvider, string format, params object[] args)
{
throw new NotImplementedException();
}
public void DebugFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void Error(object message)
{
log.Error(message);
}
public void Error(object message, Exception exception)
{
log.Error(exception, message.ToString());
}
public void Error(Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Error(Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void Error(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Error(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void ErrorFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void ErrorFormat(string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void ErrorFormat(IFormatProvider formatProvider, string format, params object[] args)
{
throw new NotImplementedException();
}
public void ErrorFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void Fatal(object message)
{
log.Fatal(message);
}
public void Fatal(object message, Exception exception)
{
log.Fatal(exception, message.ToString());
}
public void Fatal(Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Fatal(Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void Fatal(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Fatal(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void FatalFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void FatalFormat(string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void FatalFormat(IFormatProvider formatProvider, string format, params object[] args)
{
throw new NotImplementedException();
}
public void FatalFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void Info(object message)
{
log.Info(message);
}
public void Info(object message, Exception exception)
{
log.Info(exception, message.ToString());
}
public void Info(Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Info(Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void Info(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Info(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void InfoFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void InfoFormat(string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void InfoFormat(IFormatProvider formatProvider, string format, params object[] args)
{
throw new NotImplementedException();
}
public void InfoFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void Trace(object message)
{
log.Trace(message);
}
public void Trace(object message, Exception exception)
{
log.Trace(exception, message.ToString());
}
public void Trace(Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Trace(Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void Trace(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Trace(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void TraceFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void TraceFormat(string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void TraceFormat(IFormatProvider formatProvider, string format, params object[] args)
{
throw new NotImplementedException();
}
public void TraceFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void Warn(object message)
{
log.Warn(message);
}
public void Warn(object message, Exception exception)
{
log.Warn(exception, message.ToString());
}
public void Warn(Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Warn(Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void Warn(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback)
{
throw new NotImplementedException();
}
public void Warn(IFormatProvider formatProvider, Action<FormatMessageHandler> formatMessageCallback, Exception exception)
{
throw new NotImplementedException();
}
public void WarnFormat(string format, params object[] args)
{
throw new NotImplementedException();
}
public void WarnFormat(string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
public void WarnFormat(IFormatProvider formatProvider, string format, params object[] args)
{
throw new NotImplementedException();
}
public void WarnFormat(IFormatProvider formatProvider, string format, Exception exception, params object[] args)
{
throw new NotImplementedException();
}
}
Ensuite, je peux configurer NLog comme enregistreur en faisant:
Common.Logging.LogManager.Adapter = new CommonLoggingNLogAdapter();
Ceci est une solution temporaire que j'applique jusqu'à ce qu'il y ait une version officielle.
Merci pour votre réponse. J'essaie d'utiliser une bibliothèque qui utilise Common.Logging en interne, donc je vais tester votre première alternative – Jawen