using MediaBrowser.Model.Logging;
using ServiceStack.Logging;
using System;
namespace MediaBrowser.Server.Implementations.HttpServer
{
///
/// Class ServerLogFactory
///
public class ServerLogFactory : ILogFactory
{
///
/// The _log manager
///
private readonly ILogManager _logManager;
///
/// Initializes a new instance of the class.
///
/// The log manager.
public ServerLogFactory(ILogManager logManager)
{
_logManager = logManager;
}
///
/// Gets the logger.
///
/// Name of the type.
/// ILog.
public ILog GetLogger(string typeName)
{
return new ServerLogger(_logManager.GetLogger(typeName));
}
///
/// Gets the logger.
///
/// The type.
/// ILog.
public ILog GetLogger(Type type)
{
return GetLogger(type.Name);
}
}
///
/// Class ServerLogger
///
public class ServerLogger : ILog
{
///
/// The _logger
///
private readonly ILogger _logger;
///
/// Initializes a new instance of the class.
///
/// The logger.
public ServerLogger(ILogger logger)
{
_logger = logger;
}
///
/// Logs a Debug message and exception.
///
/// The message.
/// The exception.
public void Debug(object message, Exception exception)
{
_logger.ErrorException(GetMesssage(message), exception);
}
///
/// Logs a Debug message.
///
/// The message.
public void Debug(object message)
{
// Way too verbose. Can always make this configurable if needed again.
//_logger.Debug(GetMesssage(message));
}
///
/// Logs a Debug format message.
///
/// The format.
/// The args.
public void DebugFormat(string format, params object[] args)
{
// Way too verbose. Can always make this configurable if needed again.
//_logger.Debug(format, args);
}
///
/// Logs a Error message and exception.
///
/// The message.
/// The exception.
public void Error(object message, Exception exception)
{
_logger.ErrorException(GetMesssage(message), exception);
}
///
/// Logs a Error message.
///
/// The message.
public void Error(object message)
{
_logger.Error(GetMesssage(message));
}
///
/// Logs a Error format message.
///
/// The format.
/// The args.
public void ErrorFormat(string format, params object[] args)
{
_logger.Error(format, args);
}
///
/// Logs a Fatal message and exception.
///
/// The message.
/// The exception.
public void Fatal(object message, Exception exception)
{
_logger.FatalException(GetMesssage(message), exception);
}
///
/// Logs a Fatal message.
///
/// The message.
public void Fatal(object message)
{
_logger.Fatal(GetMesssage(message));
}
///
/// Logs a Error format message.
///
/// The format.
/// The args.
public void FatalFormat(string format, params object[] args)
{
_logger.Fatal(format, args);
}
///
/// Logs an Info message and exception.
///
/// The message.
/// The exception.
public void Info(object message, Exception exception)
{
_logger.ErrorException(GetMesssage(message), exception);
}
///
/// Logs an Info message and exception.
///
/// The message.
public void Info(object message)
{
_logger.Info(GetMesssage(message));
}
///
/// Logs an Info format message.
///
/// The format.
/// The args.
public void InfoFormat(string format, params object[] args)
{
_logger.Info(format, args);
}
///
/// Gets or sets a value indicating whether this instance is debug enabled.
///
/// true if this instance is debug enabled; otherwise, false.
public bool IsDebugEnabled
{
get { return true; }
}
///
/// Logs a Warning message and exception.
///
/// The message.
/// The exception.
public void Warn(object message, Exception exception)
{
_logger.ErrorException(GetMesssage(message), exception);
}
///
/// Logs a Warning message.
///
/// The message.
public void Warn(object message)
{
_logger.Warn(GetMesssage(message));
}
///
/// Logs a Warning format message.
///
/// The format.
/// The args.
public void WarnFormat(string format, params object[] args)
{
_logger.Warn(format, args);
}
///
/// Gets the messsage.
///
/// The o.
/// System.String.
private string GetMesssage(object o)
{
return o == null ? string.Empty : o.ToString();
}
}
}