From 2e511fba839e86d9393e5eeb10795f1b0aed7ce0 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 20 Sep 2013 21:04:14 -0400 Subject: support run as service --- .../BaseApplicationHost.cs | 19 +++++----- .../BaseApplicationPaths.cs | 9 +++++ .../Logging/NlogManager.cs | 41 ++++++++++++++++++++-- 3 files changed, 56 insertions(+), 13 deletions(-) (limited to 'MediaBrowser.Common.Implementations') diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index f333eb22c..c0ac6a4b3 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -1,6 +1,5 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; -using MediaBrowser.Common.Implementations.Logging; using MediaBrowser.Common.Implementations.NetworkManagement; using MediaBrowser.Common.Implementations.ScheduledTasks; using MediaBrowser.Common.Implementations.Security; @@ -71,7 +70,7 @@ namespace MediaBrowser.Common.Implementations /// Gets the application paths. /// /// The application paths. - protected TApplicationPathsType ApplicationPaths = new TApplicationPathsType(); + protected TApplicationPathsType ApplicationPaths { get; private set; } /// /// The container @@ -153,11 +152,12 @@ namespace MediaBrowser.Common.Implementations /// /// Initializes a new instance of the class. /// - protected BaseApplicationHost() + protected BaseApplicationHost(TApplicationPathsType applicationPaths, ILogManager logManager) { FailedAssemblies = new List(); - LogManager = new NlogManager(ApplicationPaths.LogDirectoryPath, LogFilePrefixName); + ApplicationPaths = applicationPaths; + LogManager = logManager; ConfigurationManager = GetConfigurationManager(); } @@ -172,7 +172,10 @@ namespace MediaBrowser.Common.Implementations Logger = LogManager.GetLogger("App"); - LogManager.ReloadLogger(ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info); + LogManager.LogSeverity = ConfigurationManager.CommonConfiguration.EnableDebugLevelLogging + ? LogSeverity.Debug + : LogSeverity.Info; + OnLoggerLoaded(); DiscoverTypes(); @@ -211,12 +214,6 @@ namespace MediaBrowser.Common.Implementations /// IEnumerable{Assembly}. protected abstract IEnumerable GetComposablePartAssemblies(); - /// - /// Gets the name of the log file prefix. - /// - /// The name of the log file prefix. - protected abstract string LogFilePrefixName { get; } - /// /// Gets the configuration manager. /// diff --git a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs index f6667f236..c177bd1ed 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationPaths.cs @@ -26,6 +26,15 @@ namespace MediaBrowser.Common.Implementations _useDebugPath = useDebugPath; } + /// + /// Initializes a new instance of the class. + /// + /// The program data path. + protected BaseApplicationPaths(string programDataPath) + { + _programDataPath = programDataPath; + } + /// /// The _program data path /// diff --git a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs index cd3dc5c16..109e85d80 100644 --- a/MediaBrowser.Common.Implementations/Logging/NlogManager.cs +++ b/MediaBrowser.Common.Implementations/Logging/NlogManager.cs @@ -1,10 +1,10 @@ -using System.Linq; -using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Logging; using NLog; using NLog.Config; using NLog.Targets; using System; using System.IO; +using System.Linq; using System.Threading.Tasks; namespace MediaBrowser.Common.Implementations.Logging @@ -45,6 +45,41 @@ namespace MediaBrowser.Common.Implementations.Logging LogFilePrefix = logFileNamePrefix; } + private LogSeverity _severity = LogSeverity.Debug; + public LogSeverity LogSeverity + { + get + { + return _severity; + } + set + { + var changed = _severity != value; + + _severity = value; + + if (changed) + { + UpdateLogLevel(value); + } + } + } + + private void UpdateLogLevel(LogSeverity newLevel) + { + var level = GetLogLevel(newLevel); + + var rules = LogManager.Configuration.LoggingRules; + + foreach (var rule in rules) + { + if (!rule.IsLoggingEnabledForLevel(level)) + { + rule.EnableLoggingForLevel(level); + } + } + } + /// /// Adds the file target. /// @@ -154,6 +189,8 @@ namespace MediaBrowser.Common.Implementations.Logging AddFileTarget(LogFilePath, level); + LogSeverity = level; + if (LoggerLoaded != null) { Task.Run(() => -- cgit v1.2.3