support run as service

This commit is contained in:
Luke Pulverenti
2013-09-20 21:04:14 -04:00
parent b5615cb233
commit 2e511fba83
16 changed files with 550 additions and 205 deletions

View File

@@ -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);
}
}
}
/// <summary>
/// Adds the file target.
/// </summary>
@@ -154,6 +189,8 @@ namespace MediaBrowser.Common.Implementations.Logging
AddFileTarget(LogFilePath, level);
LogSeverity = level;
if (LoggerLoaded != null)
{
Task.Run(() =>