I'm currently using Common.Logging version 3.4.0-beta2 and NLog 5.0.0-beta07 on netcoreapp1.1. (its and ASP Net Core mvc project) I cannot find Common.Logging.NLog specific version for that case.
In case it is not yet available, which log file option do I have as adapter for net core?
I finally created two classes:
public class CommonLoggingNLogAdapter : ILoggerFactoryAdapter
{
public ILog GetLogger(Type type)
{
return new NLogAdapter(type);
}
public ILog GetLogger(string key)
{
return new NLogAdapter(key);
}
}
and
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();
}
}
Then I can configure NLog as logger by doing:
Common.Logging.LogManager.Adapter = new CommonLoggingNLogAdapter();
This is a temporary solution I'm implementing until there is an official release.