From fdafa596832eae13cebcf5bbe5fa867f7ba068f0 Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Thu, 21 Feb 2013 20:26:35 -0500 Subject: Removed System.Windows.Forms dependancy from Common. Almost done removing NLog dependancy. --- MediaBrowser.Common/Kernel/BaseKernel.cs | 82 ++++++++------------------------ 1 file changed, 20 insertions(+), 62 deletions(-) (limited to 'MediaBrowser.Common/Kernel/BaseKernel.cs') diff --git a/MediaBrowser.Common/Kernel/BaseKernel.cs b/MediaBrowser.Common/Kernel/BaseKernel.cs index 2b2063b55..a4ac70749 100644 --- a/MediaBrowser.Common/Kernel/BaseKernel.cs +++ b/MediaBrowser.Common/Kernel/BaseKernel.cs @@ -9,9 +9,6 @@ using MediaBrowser.Common.Serialization; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Logging; using MediaBrowser.Model.System; -using NLog; -using NLog.Config; -using NLog.Targets; using System; using System.Collections.Generic; using System.ComponentModel.Composition; @@ -40,11 +37,6 @@ namespace MediaBrowser.Common.Kernel /// public event EventHandler HasPendingRestartChanged; - /// - /// Notifiies the containing application that a restart has been requested - /// - public event EventHandler ApplicationRestartRequested; - #region ConfigurationUpdated Event /// /// Occurs when [configuration updated]. @@ -341,6 +333,12 @@ namespace MediaBrowser.Common.Kernel /// The logger. protected ILogger Logger { get; private set; } + /// + /// Gets or sets the application host. + /// + /// The application host. + protected IApplicationHost ApplicationHost { get; private set; } + /// /// Gets the assemblies. /// @@ -350,10 +348,17 @@ namespace MediaBrowser.Common.Kernel /// /// Initializes a new instance of the class. /// + /// The app host. /// The iso manager. /// The logger. - protected BaseKernel(IIsoManager isoManager, ILogger logger) + /// isoManager + protected BaseKernel(IApplicationHost appHost, IIsoManager isoManager, ILogger logger) { + if (appHost == null) + { + throw new ArgumentNullException("appHost"); + } + if (isoManager == null) { throw new ArgumentNullException("isoManager"); @@ -363,7 +368,8 @@ namespace MediaBrowser.Common.Kernel { throw new ArgumentNullException("logger"); } - + + ApplicationHost = appHost; IsoManager = isoManager; Logger = logger; } @@ -440,42 +446,11 @@ namespace MediaBrowser.Common.Kernel /// public void ReloadLogger() { - DisposeLogger(); - - LogFilePath = Path.Combine(ApplicationPaths.LogDirectoryPath, KernelContext + "-" + DateTime.Now.Ticks + ".log"); - - var logFile = new FileTarget(); - - logFile.FileName = LogFilePath; - logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}"; - - AddLogTarget(logFile, "ApplicationLogFile"); - + ApplicationHost.ReloadLogger(); + OnLoggerLoaded(); } - /// - /// Adds the log target. - /// - /// The target. - /// The name. - private void AddLogTarget(Target target, string name) - { - var config = LogManager.Configuration; - - config.RemoveTarget(name); - - target.Name = name; - config.AddTarget(name, target); - - var level = Configuration.EnableDebugLevelLogging ? LogLevel.Debug : LogLevel.Info; - - var rule = new LoggingRule("*", level, target); - config.LoggingRules.Add(rule); - - LogManager.Configuration = config; - } - /// /// Uses MEF to locate plugins /// Subclasses can use this to locate types within plugins @@ -588,7 +563,7 @@ namespace MediaBrowser.Common.Kernel foreach (var task in ScheduledTasks) { - task.Initialize(this); + task.Initialize(this, Logger); } // Start-up each plugin @@ -707,23 +682,6 @@ namespace MediaBrowser.Common.Kernel } } - /// - /// Disposes all logger resources - /// - private void DisposeLogger() - { - // Dispose all current loggers - var listeners = Trace.Listeners.OfType().ToList(); - - Trace.Listeners.Clear(); - - foreach (var listener in listeners) - { - listener.Dispose(); - } - - } - /// /// Gets the current application version /// @@ -759,7 +717,7 @@ namespace MediaBrowser.Common.Kernel { Logger.Info("Restarting the application"); - EventHelper.QueueEventIfNotNull(ApplicationRestartRequested, this, EventArgs.Empty, Logger); + ApplicationHost.Restart(); } /// -- cgit v1.2.3