using System;
using System.IO;
namespace ServiceStack.Logging.Log4Net
{
///
/// ILogFactory that creates an Log4Net ILog logger
///
public class Log4NetFactory : ILogFactory
{
///
/// Initializes a new instance of the class.
///
public Log4NetFactory() : this(false) { }
///
/// Initializes a new instance of the class.
///
/// if set to true [will use the xml definition in App.Config to configure log4 net].
public Log4NetFactory(bool configureLog4Net)
{
if (configureLog4Net)
{
log4net.Config.XmlConfigurator.Configure();
}
}
///
/// Initializes a new instance of the class.
///
/// The log4 net configuration file to load and watch. If not found configures from App.Config.
public Log4NetFactory(string log4NetConfigurationFile)
{
//Restart logging if necessary
log4net.Repository.ILoggerRepository rootRepository = log4net.LogManager.GetRepository();
if (rootRepository != null)
rootRepository.Shutdown();
if (File.Exists(log4NetConfigurationFile))
log4net.Config.XmlConfigurator.ConfigureAndWatch(new FileInfo(log4NetConfigurationFile));
else
log4net.Config.XmlConfigurator.Configure();
}
///
/// Gets the logger.
///
/// The type.
///
public ILog GetLogger(Type type)
{
return new Log4NetLogger(type);
}
///
/// Gets the logger.
///
/// Name of the type.
///
public ILog GetLogger(string typeName)
{
return new Log4NetLogger(typeName);
}
}
}