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,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.
/// </summary>
/// <value>The application paths.</value>
protected TApplicationPathsType ApplicationPaths = new TApplicationPathsType();
protected TApplicationPathsType ApplicationPaths { get; private set; }
/// <summary>
/// The container
@@ -153,11 +152,12 @@ namespace MediaBrowser.Common.Implementations
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationHost{TApplicationPathsType}"/> class.
/// </summary>
protected BaseApplicationHost()
protected BaseApplicationHost(TApplicationPathsType applicationPaths, ILogManager logManager)
{
FailedAssemblies = new List<string>();
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
/// <returns>IEnumerable{Assembly}.</returns>
protected abstract IEnumerable<Assembly> GetComposablePartAssemblies();
/// <summary>
/// Gets the name of the log file prefix.
/// </summary>
/// <value>The name of the log file prefix.</value>
protected abstract string LogFilePrefixName { get; }
/// <summary>
/// Gets the configuration manager.
/// </summary>

View File

@@ -26,6 +26,15 @@ namespace MediaBrowser.Common.Implementations
_useDebugPath = useDebugPath;
}
/// <summary>
/// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
/// </summary>
/// <param name="programDataPath">The program data path.</param>
protected BaseApplicationPaths(string programDataPath)
{
_programDataPath = programDataPath;
}
/// <summary>
/// The _program data path
/// </summary>

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(() =>