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 --- .../Logging/NlogManager.cs | 41 ++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'MediaBrowser.Common.Implementations/Logging') 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