using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Web;
using log4net;
using log4net.Config;
namespace Umbraco.Core.Logging
{
///
/// Used for logging
///
public class Logger : ILogger
{
public Logger(FileInfo log4NetConfigFile)
:this()
{
XmlConfigurator.Configure(log4NetConfigFile);
}
private Logger()
{
//Add custom global properties to the log4net context that we can use in our logging output
log4net.GlobalContext.Properties["processId"] = Process.GetCurrentProcess().Id;
log4net.GlobalContext.Properties["appDomainId"] = AppDomain.CurrentDomain.Id;
}
///
/// Creates a logger with the default log4net configuration discovered (i.e. from the web.config)
///
///
public static Logger CreateWithDefaultLog4NetConfiguration()
{
return new Logger();
}
///
/// Returns a logger for the type specified
///
///
///
internal ILog LoggerFor()
{
return LogManager.GetLogger(typeof(T));
}
///
/// Returns a logger for the object's type
///
///
///
internal ILog LoggerFor(object getTypeFromInstance)
{
if (getTypeFromInstance == null) throw new ArgumentNullException("getTypeFromInstance");
return LogManager.GetLogger(getTypeFromInstance.GetType());
}
public void Error(Type callingType, string message, Exception exception)
{
var logger = LogManager.GetLogger(callingType);
if (logger != null)
logger.Error((message), exception);
}
public void Warn(Type callingType, string message, params Func