2011-10-24 05:54:09 +00:00
|
|
|
|
using System.IO;
|
2011-04-10 02:44:01 +00:00
|
|
|
|
using Ninject;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
using NLog;
|
|
|
|
|
using NLog.Config;
|
2011-10-29 04:54:33 +00:00
|
|
|
|
using NzbDrone.Common;
|
2011-10-21 05:04:26 +00:00
|
|
|
|
using NzbDrone.Core.Providers;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Instrumentation
|
|
|
|
|
{
|
2011-11-03 05:04:14 +00:00
|
|
|
|
public class LogConfiguration
|
2010-10-24 07:46:58 +00:00
|
|
|
|
{
|
2011-11-03 05:04:14 +00:00
|
|
|
|
private readonly PathProvider _pathProvider;
|
2011-11-08 20:12:54 +00:00
|
|
|
|
private readonly DatabaseTarget _databaseTarget;
|
2011-10-24 05:54:09 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
public LogConfiguration(PathProvider pathProvider, DatabaseTarget databaseTarget)
|
2011-11-03 05:04:14 +00:00
|
|
|
|
{
|
|
|
|
|
_pathProvider = pathProvider;
|
2011-11-08 20:12:54 +00:00
|
|
|
|
_databaseTarget = databaseTarget;
|
2011-11-03 05:04:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Setup()
|
2010-10-24 07:46:58 +00:00
|
|
|
|
{
|
2011-10-24 05:54:09 +00:00
|
|
|
|
if (Common.EnviromentProvider.IsProduction)
|
2010-10-24 07:46:58 +00:00
|
|
|
|
{
|
2011-10-24 05:54:09 +00:00
|
|
|
|
LogManager.ThrowExceptions = false;
|
2010-10-24 07:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-03 05:04:14 +00:00
|
|
|
|
LogManager.Configuration = new XmlLoggingConfiguration(_pathProvider.LogConfigFile, false);
|
2011-10-24 05:54:09 +00:00
|
|
|
|
|
|
|
|
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
|
|
|
|
|
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
|
2011-06-13 03:45:22 +00:00
|
|
|
|
|
2011-11-08 20:12:54 +00:00
|
|
|
|
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(_databaseTarget));
|
2010-10-24 07:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-10-24 05:54:09 +00:00
|
|
|
|
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)
|
2010-10-24 07:46:58 +00:00
|
|
|
|
{
|
2011-10-24 05:54:09 +00:00
|
|
|
|
LogManager.Configuration.AddTarget("DbLogger", databaseTarget);
|
|
|
|
|
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, databaseTarget));
|
|
|
|
|
Common.LogConfiguration.Reload();
|
2010-10-24 07:46:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-10 02:44:01 +00:00
|
|
|
|
}
|