Skip to content

Instantly share code, notes, and snippets.

@borrrden
Last active Mar 12, 2016
Embed
What would you like to do?
An adapter for sending Couchbase Lite logs to log4net
using System;
using Couchbase.Lite.Util;
using log4net;
namespace Couchbase.Lite.Logger
{
// Use like this -> Couchbase.Lite.Util.Log.SetLogger(new Log4NetLogger())
public sealed class Log4NetLogger : ILogger
{
private readonly ILog _internalLogger = LogManager.GetLogger("Couchbase");
#region ILogger
public void V (string tag, string msg)
{
_internalLogger.InfoFormat ("{0}: {1}", tag, msg);
}
public void V (string tag, string msg, Exception tr)
{
_internalLogger.Info (String.Format ("{0}: {1}", tag, msg), tr);
}
public void V (string tag, string format, params object[] args)
{
var realFormat = String.Format("{0}: {1}", tag, format);
_internalLogger.InfoFormat(realFormat, args);
}
public void D (string tag, string msg)
{
_internalLogger.DebugFormat ("{0}: {1}", tag, msg);
}
public void D (string tag, string msg, Exception tr)
{
_internalLogger.Debug (String.Format ("{0}: {1}", tag, msg), tr);
}
public void D (string tag, string format, params object[] args)
{
var realFormat = String.Format("{0}: {1}", tag, format);
_internalLogger.DebugFormat(realFormat, args);
}
public void I (string tag, string msg)
{
_internalLogger.InfoFormat ("{0}: {1}", tag, msg);
}
public void I (string tag, string msg, Exception tr)
{
_internalLogger.Info (String.Format ("{0}: {1}", tag, msg), tr);
}
public void I (string tag, string format, params object[] args)
{
var realFormat = String.Format("{0}: {1}", tag, format);
_internalLogger.InfoFormat(realFormat, args);
}
public void W (string tag, string msg)
{
_internalLogger.WarnFormat ("{0}: {1}", tag, msg);
}
public void W (string tag, Exception tr)
{
_internalLogger.Warn (tag, tr);
}
public void W (string tag, string msg, Exception tr)
{
_internalLogger.Warn (String.Format ("{0}: {1}", tag, msg), tr);
}
public void W (string tag, string format, params object[] args)
{
var realFormat = String.Format("{0}: {1}", tag, format);
_internalLogger.WarnFormat(realFormat, args);
}
public void E (string tag, string msg)
{
_internalLogger.ErrorFormat ("{0}: {1}", tag, msg);
}
public void E (string tag, string msg, Exception tr)
{
_internalLogger.Error (String.Format ("{0}: {1}", tag, msg), tr);
}
public void E (string tag, string format, params object[] args)
{
var realFormat = String.Format("{0}: {1}", tag, format);
_internalLogger.ErrorFormat(realFormat, args);
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment