Lots of initialization, configuration clean up.

This commit is contained in:
kay.one 2011-11-13 16:22:18 -08:00
commit 51518787d8
74 changed files with 316 additions and 279 deletions

View file

@ -1,4 +1,5 @@
using System;
using NLog.Config;
using Ninject;
using NLog;
using NLog.Targets;
@ -19,6 +20,15 @@ namespace NzbDrone.Core.Instrumentation
_database = database;
}
public void Register()
{
LogManager.Configuration.AddTarget("DbLogger", this);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, this));
LogManager.ConfigurationReloaded += (sender, args) => Register();
LogConfiguration.Reload();
}
protected override void Write(LogEventInfo logEvent)

View file

@ -1,49 +0,0 @@
using System.IO;
using Ninject;
using NLog;
using NLog.Config;
using NzbDrone.Common;
using NzbDrone.Core.Providers;
namespace NzbDrone.Core.Instrumentation
{
public class LogConfiguration
{
private readonly EnviromentProvider _enviromentProvider;
private readonly DatabaseTarget _databaseTarget;
public LogConfiguration(EnviromentProvider enviromentProvider, DatabaseTarget databaseTarget)
{
_enviromentProvider = enviromentProvider;
_databaseTarget = databaseTarget;
}
public void Setup()
{
if (Common.EnviromentProvider.IsProduction)
{
LogManager.ThrowExceptions = false;
}
LogManager.Configuration = new XmlLoggingConfiguration(_enviromentProvider.GetNlogConfigPath(), false);
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Web.MvcApplication");
Common.LogConfiguration.RegisterConsoleLogger(LogLevel.Info, "NzbDrone.Core.CentralDispatch");
LogManager.ConfigurationReloaded += ((s, e) => RegisterDatabaseLogger(_databaseTarget));
}
public static void RegisterDatabaseLogger(DatabaseTarget databaseTarget)
{
LogManager.Configuration.AddTarget("DbLogger", databaseTarget);
LogManager.Configuration.LoggingRules.Add(new LoggingRule("*", LogLevel.Debug, databaseTarget));
Reload();
}
public static void Reload()
{
Common.LogConfiguration.Reload();
}
}
}