fix log window setting
This commit is contained in:
parent
cbb2f00da5
commit
0f1ec5b586
|
@ -26,20 +26,18 @@ namespace MediaBrowser.Api.WebSocket
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _kernel
|
/// The _kernel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly ILogManager _logManager;
|
||||||
private readonly IKernel _kernel;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="LogFileWebSocketListener" /> class.
|
/// Initializes a new instance of the <see cref="LogFileWebSocketListener" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
/// <param name="kernel">The kernel.</param>
|
/// <param name="logManager">The log manager.</param>
|
||||||
public LogFileWebSocketListener(ILogger logger, IApplicationHost host, IKernel kernel)
|
public LogFileWebSocketListener(ILogger logger, ILogManager logManager)
|
||||||
: base(logger)
|
: base(logger)
|
||||||
{
|
{
|
||||||
_appHost = host;
|
_logManager = logManager;
|
||||||
_kernel = kernel;
|
_logManager.LoggerLoaded += kernel_LoggerLoaded;
|
||||||
kernel.LoggerLoaded += kernel_LoggerLoaded;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -49,9 +47,9 @@ namespace MediaBrowser.Api.WebSocket
|
||||||
/// <returns>IEnumerable{System.String}.</returns>
|
/// <returns>IEnumerable{System.String}.</returns>
|
||||||
protected override async Task<IEnumerable<string>> GetDataToSend(LogFileWebSocketState state)
|
protected override async Task<IEnumerable<string>> GetDataToSend(LogFileWebSocketState state)
|
||||||
{
|
{
|
||||||
if (!string.Equals(_appHost.LogFilePath, state.LastLogFilePath))
|
if (!string.Equals(_logManager.LogFilePath, state.LastLogFilePath))
|
||||||
{
|
{
|
||||||
state.LastLogFilePath = _appHost.LogFilePath;
|
state.LastLogFilePath = _logManager.LogFilePath;
|
||||||
state.StartLine = 0;
|
state.StartLine = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +68,7 @@ namespace MediaBrowser.Api.WebSocket
|
||||||
{
|
{
|
||||||
if (dispose)
|
if (dispose)
|
||||||
{
|
{
|
||||||
_kernel.LoggerLoaded -= kernel_LoggerLoaded;
|
_logManager.LoggerLoaded -= kernel_LoggerLoaded;
|
||||||
}
|
}
|
||||||
base.Dispose(dispose);
|
base.Dispose(dispose);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using MediaBrowser.Common.Kernel;
|
||||||
using MediaBrowser.Model.Logging;
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using SimpleInjector;
|
using SimpleInjector;
|
||||||
|
@ -18,6 +19,18 @@ namespace MediaBrowser.Common.Implementations
|
||||||
/// <value>The logger.</value>
|
/// <value>The logger.</value>
|
||||||
public ILogger Logger { get; protected set; }
|
public ILogger Logger { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the log manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The log manager.</value>
|
||||||
|
public ILogManager LogManager { get; protected set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the application paths.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The application paths.</value>
|
||||||
|
protected IApplicationPaths ApplicationPaths { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The container
|
/// The container
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -45,6 +58,12 @@ namespace MediaBrowser.Common.Implementations
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected readonly List<IDisposable> DisposableParts = new List<IDisposable>();
|
protected readonly List<IDisposable> DisposableParts = new List<IDisposable>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets a value indicating whether this instance is first run.
|
||||||
|
/// </summary>
|
||||||
|
/// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
|
||||||
|
public bool IsFirstRun { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _protobuf serializer initialized
|
/// The _protobuf serializer initialized
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -82,6 +101,16 @@ namespace MediaBrowser.Common.Implementations
|
||||||
protected BaseApplicationHost()
|
protected BaseApplicationHost()
|
||||||
{
|
{
|
||||||
FailedAssemblies = new List<string>();
|
FailedAssemblies = new List<string>();
|
||||||
|
|
||||||
|
ApplicationPaths = GetApplicationPaths();
|
||||||
|
|
||||||
|
LogManager = GetLogManager();
|
||||||
|
|
||||||
|
Logger = LogManager.GetLogger("App");
|
||||||
|
|
||||||
|
IsFirstRun = !File.Exists(ApplicationPaths.SystemConfigurationFilePath);
|
||||||
|
|
||||||
|
DiscoverTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -90,6 +119,18 @@ namespace MediaBrowser.Common.Implementations
|
||||||
/// <returns>IEnumerable{Assembly}.</returns>
|
/// <returns>IEnumerable{Assembly}.</returns>
|
||||||
protected abstract IEnumerable<Assembly> GetComposablePartAssemblies();
|
protected abstract IEnumerable<Assembly> GetComposablePartAssemblies();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the log manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>ILogManager.</returns>
|
||||||
|
protected abstract ILogManager GetLogManager();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the application paths.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>IApplicationPaths.</returns>
|
||||||
|
protected abstract IApplicationPaths GetApplicationPaths();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Discovers the types.
|
/// Discovers the types.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -14,25 +14,32 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||||
public class ReloadLoggerFileTask : IScheduledTask
|
public class ReloadLoggerFileTask : IScheduledTask
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the kernel.
|
/// Gets or sets the log manager.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The kernel.</value>
|
/// <value>The log manager.</value>
|
||||||
private IKernel Kernel { get; set; }
|
private ILogManager LogManager { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the logger.
|
/// Gets or sets the logger.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The logger.</value>
|
/// <value>The logger.</value>
|
||||||
private ILogger Logger { get; set; }
|
private ILogger Logger { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the kernel.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The kernel.</value>
|
||||||
|
private IKernel Kernel { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class.
|
/// Initializes a new instance of the <see cref="ReloadLoggerFileTask" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="kernel">The kernel.</param>
|
/// <param name="logManager">The logManager.</param>
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
public ReloadLoggerFileTask(IKernel kernel, ILogger logger)
|
/// <param name="kernel">The kernel.</param>
|
||||||
|
public ReloadLoggerFileTask(ILogManager logManager, ILogger logger, IKernel kernel)
|
||||||
{
|
{
|
||||||
Kernel = kernel;
|
LogManager = logManager;
|
||||||
Logger = logger;
|
Logger = logger;
|
||||||
|
Kernel = kernel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -57,8 +64,8 @@ namespace MediaBrowser.Common.Implementations.ScheduledTasks.Tasks
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
progress.Report(0);
|
progress.Report(0);
|
||||||
|
|
||||||
return Task.Run(() => Kernel.ReloadLogger());
|
return Task.Run(() => LogManager.ReloadLogger(Kernel.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -42,20 +42,6 @@ namespace MediaBrowser.Common.Kernel
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region LoggerLoaded Event
|
|
||||||
/// <summary>
|
|
||||||
/// Fires whenever the logger is loaded
|
|
||||||
/// </summary>
|
|
||||||
public event EventHandler LoggerLoaded;
|
|
||||||
/// <summary>
|
|
||||||
/// Called when [logger loaded].
|
|
||||||
/// </summary>
|
|
||||||
private void OnLoggerLoaded()
|
|
||||||
{
|
|
||||||
EventHelper.QueueEventIfNotNull(LoggerLoaded, this, EventArgs.Empty, Logger);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region ReloadBeginning Event
|
#region ReloadBeginning Event
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Fires whenever the kernel begins reloading
|
/// Fires whenever the kernel begins reloading
|
||||||
|
@ -277,16 +263,6 @@ namespace MediaBrowser.Common.Kernel
|
||||||
return Task.FromResult<object>(null);
|
return Task.FromResult<object>(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes and reloads all loggers
|
|
||||||
/// </summary>
|
|
||||||
public void ReloadLogger()
|
|
||||||
{
|
|
||||||
ApplicationHost.ReloadLogger();
|
|
||||||
|
|
||||||
OnLoggerLoaded();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Composes the parts with ioc container.
|
/// Composes the parts with ioc container.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -16,23 +16,12 @@ namespace MediaBrowser.Common.Kernel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void Restart();
|
void Restart();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reloads the logger.
|
|
||||||
/// </summary>
|
|
||||||
void ReloadLogger();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the application version.
|
/// Gets the application version.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <value>The application version.</value>
|
/// <value>The application version.</value>
|
||||||
Version ApplicationVersion { get; }
|
Version ApplicationVersion { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the log file path.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The log file path.</value>
|
|
||||||
string LogFilePath { get; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether this instance can self update.
|
/// Gets or sets a value indicating whether this instance can self update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -53,11 +53,6 @@ namespace MediaBrowser.Common.Kernel
|
||||||
/// <returns>SystemInfo.</returns>
|
/// <returns>SystemInfo.</returns>
|
||||||
SystemInfo GetSystemInfo();
|
SystemInfo GetSystemInfo();
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reloads the logger.
|
|
||||||
/// </summary>
|
|
||||||
void ReloadLogger();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Called when [application updated].
|
/// Called when [application updated].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -105,11 +100,6 @@ namespace MediaBrowser.Common.Kernel
|
||||||
/// <value>The web socket listeners.</value>
|
/// <value>The web socket listeners.</value>
|
||||||
IEnumerable<IWebSocketListener> WebSocketListeners { get; }
|
IEnumerable<IWebSocketListener> WebSocketListeners { get; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Occurs when [logger loaded].
|
|
||||||
/// </summary>
|
|
||||||
event EventHandler LoggerLoaded;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Occurs when [reload completed].
|
/// Occurs when [reload completed].
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -531,18 +531,9 @@ namespace MediaBrowser.Controller
|
||||||
/// <param name="config">The config.</param>
|
/// <param name="config">The config.</param>
|
||||||
public void UpdateConfiguration(ServerConfiguration config)
|
public void UpdateConfiguration(ServerConfiguration config)
|
||||||
{
|
{
|
||||||
var oldConfiguration = Configuration;
|
|
||||||
|
|
||||||
var reloadLogger = config.ShowLogWindow != oldConfiguration.ShowLogWindow;
|
|
||||||
|
|
||||||
Configuration = config;
|
Configuration = config;
|
||||||
SaveConfiguration();
|
SaveConfiguration();
|
||||||
|
|
||||||
if (reloadLogger)
|
|
||||||
{
|
|
||||||
ReloadLogger();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Validate currently executing providers, in the background
|
// Validate currently executing providers, in the background
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,27 +1,62 @@
|
||||||
using NLog;
|
using MediaBrowser.Model.Logging;
|
||||||
|
using NLog;
|
||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace MediaBrowser.Logging.Nlog
|
namespace MediaBrowser.Logging.Nlog
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Class NlogManager
|
/// Class NlogManager
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class NlogManager
|
public class NlogManager : ILogManager
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when [logger loaded].
|
||||||
|
/// </summary>
|
||||||
|
public event EventHandler LoggerLoaded;
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the log directory.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The log directory.</value>
|
||||||
|
private string LogDirectory { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the log file prefix.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The log file prefix.</value>
|
||||||
|
private string LogFilePrefix { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the log file path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The log file path.</value>
|
||||||
|
public string LogFilePath { get; private set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Initializes a new instance of the <see cref="NlogManager" /> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="logDirectory">The log directory.</param>
|
||||||
|
/// <param name="logFileNamePrefix">The log file name prefix.</param>
|
||||||
|
public NlogManager(string logDirectory, string logFileNamePrefix)
|
||||||
|
{
|
||||||
|
LogDirectory = logDirectory;
|
||||||
|
LogFilePrefix = logFileNamePrefix;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds the file target.
|
/// Adds the file target.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path">The path.</param>
|
/// <param name="path">The path.</param>
|
||||||
/// <param name="enableDebugLogging">if set to <c>true</c> [enable debug logging].</param>
|
/// <param name="level">The level.</param>
|
||||||
public static void AddFileTarget(string path, bool enableDebugLogging)
|
private void AddFileTarget(string path, LogSeverity level)
|
||||||
{
|
{
|
||||||
var logFile = new FileTarget();
|
var logFile = new FileTarget();
|
||||||
|
|
||||||
logFile.FileName = path;
|
logFile.FileName = path;
|
||||||
logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}";
|
logFile.Layout = "${longdate}, ${level}, ${logger}, ${message}";
|
||||||
|
|
||||||
AddLogTarget(logFile, "ApplicationLogFile", enableDebugLogging);
|
AddLogTarget(logFile, "ApplicationLogFile", level);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -29,8 +64,8 @@ namespace MediaBrowser.Logging.Nlog
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="target">The target.</param>
|
/// <param name="target">The target.</param>
|
||||||
/// <param name="name">The name.</param>
|
/// <param name="name">The name.</param>
|
||||||
/// <param name="enableDebugLogging">if set to <c>true</c> [enable debug logging].</param>
|
/// <param name="level">The level.</param>
|
||||||
private static void AddLogTarget(Target target, string name, bool enableDebugLogging)
|
private void AddLogTarget(Target target, string name, LogSeverity level)
|
||||||
{
|
{
|
||||||
var config = LogManager.Configuration;
|
var config = LogManager.Configuration;
|
||||||
|
|
||||||
|
@ -39,12 +74,71 @@ namespace MediaBrowser.Logging.Nlog
|
||||||
target.Name = name;
|
target.Name = name;
|
||||||
config.AddTarget(name, target);
|
config.AddTarget(name, target);
|
||||||
|
|
||||||
var level = enableDebugLogging ? LogLevel.Debug : LogLevel.Info;
|
var rule = new LoggingRule("*", GetLogLevel(level), target);
|
||||||
|
|
||||||
var rule = new LoggingRule("*", level, target);
|
|
||||||
config.LoggingRules.Add(rule);
|
config.LoggingRules.Add(rule);
|
||||||
|
|
||||||
LogManager.Configuration = config;
|
LogManager.Configuration = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the logger.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <returns>ILogger.</returns>
|
||||||
|
public ILogger GetLogger(string name)
|
||||||
|
{
|
||||||
|
return new NLogger(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the log level.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="severity">The severity.</param>
|
||||||
|
/// <returns>LogLevel.</returns>
|
||||||
|
/// <exception cref="System.ArgumentException">Unrecognized LogSeverity</exception>
|
||||||
|
private LogLevel GetLogLevel(LogSeverity severity)
|
||||||
|
{
|
||||||
|
switch (severity)
|
||||||
|
{
|
||||||
|
case LogSeverity.Debug:
|
||||||
|
return LogLevel.Debug;
|
||||||
|
case LogSeverity.Error:
|
||||||
|
return LogLevel.Error;
|
||||||
|
case LogSeverity.Fatal:
|
||||||
|
return LogLevel.Fatal;
|
||||||
|
case LogSeverity.Info:
|
||||||
|
return LogLevel.Info;
|
||||||
|
case LogSeverity.Warn:
|
||||||
|
return LogLevel.Warn;
|
||||||
|
default:
|
||||||
|
throw new ArgumentException("Unrecognized LogSeverity");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the logger.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="level">The level.</param>
|
||||||
|
public void ReloadLogger(LogSeverity level)
|
||||||
|
{
|
||||||
|
LogFilePath = Path.Combine(LogDirectory, LogFilePrefix + "-" + DateTime.Now.Ticks + ".log");
|
||||||
|
|
||||||
|
AddFileTarget(LogFilePath, level);
|
||||||
|
|
||||||
|
if (LoggerLoaded != null)
|
||||||
|
{
|
||||||
|
Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoggerLoaded(this, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
GetLogger("Logger").ErrorException("Error in LoggerLoaded event", ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
33
MediaBrowser.Model/Logging/ILogManager.cs
Normal file
33
MediaBrowser.Model/Logging/ILogManager.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace MediaBrowser.Model.Logging
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interface ILogManager
|
||||||
|
/// </summary>
|
||||||
|
public interface ILogManager
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the logger.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name.</param>
|
||||||
|
/// <returns>ILogger.</returns>
|
||||||
|
ILogger GetLogger(string name);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reloads the logger.
|
||||||
|
/// </summary>
|
||||||
|
void ReloadLogger(LogSeverity severity);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the log file path.
|
||||||
|
/// </summary>
|
||||||
|
/// <value>The log file path.</value>
|
||||||
|
string LogFilePath { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Occurs when [logger loaded].
|
||||||
|
/// </summary>
|
||||||
|
event EventHandler LoggerLoaded;
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,6 +48,7 @@
|
||||||
<Compile Include="Entities\BaseItemInfo.cs" />
|
<Compile Include="Entities\BaseItemInfo.cs" />
|
||||||
<Compile Include="Connectivity\ClientConnectionInfo.cs" />
|
<Compile Include="Connectivity\ClientConnectionInfo.cs" />
|
||||||
<Compile Include="Connectivity\ClientType.cs" />
|
<Compile Include="Connectivity\ClientType.cs" />
|
||||||
|
<Compile Include="Logging\ILogManager.cs" />
|
||||||
<Compile Include="MediaInfo\BlurayDiscInfo.cs" />
|
<Compile Include="MediaInfo\BlurayDiscInfo.cs" />
|
||||||
<Compile Include="Entities\ChapterInfo.cs" />
|
<Compile Include="Entities\ChapterInfo.cs" />
|
||||||
<Compile Include="Entities\LocationType.cs" />
|
<Compile Include="Entities\LocationType.cs" />
|
||||||
|
|
|
@ -12,6 +12,7 @@ using MediaBrowser.Controller;
|
||||||
using MediaBrowser.IsoMounter;
|
using MediaBrowser.IsoMounter;
|
||||||
using MediaBrowser.Logging.Nlog;
|
using MediaBrowser.Logging.Nlog;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
|
using MediaBrowser.Model.Logging;
|
||||||
using MediaBrowser.Model.MediaInfo;
|
using MediaBrowser.Model.MediaInfo;
|
||||||
using MediaBrowser.Model.Serialization;
|
using MediaBrowser.Model.Serialization;
|
||||||
using MediaBrowser.Model.System;
|
using MediaBrowser.Model.System;
|
||||||
|
@ -39,12 +40,6 @@ namespace MediaBrowser.ServerApplication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ApplicationHost : BaseApplicationHost, IApplicationHost
|
public class ApplicationHost : BaseApplicationHost, IApplicationHost
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Gets or sets the log file path.
|
|
||||||
/// </summary>
|
|
||||||
/// <value>The log file path.</value>
|
|
||||||
public string LogFilePath { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the kernel.
|
/// Gets or sets the kernel.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -62,15 +57,13 @@ namespace MediaBrowser.ServerApplication
|
||||||
private readonly IXmlSerializer _xmlSerializer = new XmlSerializer();
|
private readonly IXmlSerializer _xmlSerializer = new XmlSerializer();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The _application paths
|
/// Gets the server application paths.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IServerApplicationPaths _applicationPaths = new ServerApplicationPaths();
|
/// <value>The server application paths.</value>
|
||||||
|
protected IServerApplicationPaths ServerApplicationPaths
|
||||||
/// <summary>
|
{
|
||||||
/// Gets a value indicating whether this instance is first run.
|
get { return (IServerApplicationPaths) ApplicationPaths; }
|
||||||
/// </summary>
|
}
|
||||||
/// <value><c>true</c> if this instance is first run; otherwise, <c>false</c>.</value>
|
|
||||||
public bool IsFirstRun { get; private set; }
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
|
/// Initializes a new instance of the <see cref="ApplicationHost" /> class.
|
||||||
|
@ -79,21 +72,15 @@ namespace MediaBrowser.ServerApplication
|
||||||
public ApplicationHost()
|
public ApplicationHost()
|
||||||
: base()
|
: base()
|
||||||
{
|
{
|
||||||
IsFirstRun = !File.Exists(_applicationPaths.SystemConfigurationFilePath);
|
Kernel = new Kernel(this, ServerApplicationPaths, _xmlSerializer, Logger);
|
||||||
|
|
||||||
Logger = new NLogger("App");
|
|
||||||
|
|
||||||
DiscoverTypes();
|
|
||||||
|
|
||||||
Kernel = new Kernel(this, _applicationPaths, _xmlSerializer, Logger);
|
|
||||||
|
|
||||||
var networkManager = new NetworkManager();
|
var networkManager = new NetworkManager();
|
||||||
|
|
||||||
var serverManager = new ServerManager(this, Kernel, networkManager, _jsonSerializer, Logger);
|
var serverManager = new ServerManager(this, Kernel, networkManager, _jsonSerializer, Logger);
|
||||||
|
|
||||||
var taskManager = new TaskManager(_applicationPaths, _jsonSerializer, Logger, serverManager);
|
var taskManager = new TaskManager(ApplicationPaths, _jsonSerializer, Logger, serverManager);
|
||||||
|
|
||||||
ReloadLogger();
|
LogManager.ReloadLogger(Kernel.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info);
|
||||||
|
|
||||||
Logger.Info("Version {0} initializing", ApplicationVersion);
|
Logger.Info("Version {0} initializing", ApplicationVersion);
|
||||||
|
|
||||||
|
@ -104,6 +91,24 @@ namespace MediaBrowser.ServerApplication
|
||||||
FindParts(taskManager, httpServer);
|
FindParts(taskManager, httpServer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the application paths.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>IApplicationPaths.</returns>
|
||||||
|
protected override IApplicationPaths GetApplicationPaths()
|
||||||
|
{
|
||||||
|
return new ServerApplicationPaths();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the log manager.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>ILogManager.</returns>
|
||||||
|
protected override ILogManager GetLogManager()
|
||||||
|
{
|
||||||
|
return new NlogManager(ApplicationPaths.LogDirectoryPath, "Server");
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Registers resources that classes will depend on
|
/// Registers resources that classes will depend on
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -113,14 +118,15 @@ namespace MediaBrowser.ServerApplication
|
||||||
RegisterSingleInstance(Kernel);
|
RegisterSingleInstance(Kernel);
|
||||||
|
|
||||||
RegisterSingleInstance<IApplicationHost>(this);
|
RegisterSingleInstance<IApplicationHost>(this);
|
||||||
|
RegisterSingleInstance(LogManager);
|
||||||
RegisterSingleInstance(Logger);
|
RegisterSingleInstance(Logger);
|
||||||
|
|
||||||
RegisterSingleInstance(_applicationPaths);
|
RegisterSingleInstance(ApplicationPaths);
|
||||||
RegisterSingleInstance<IApplicationPaths>(_applicationPaths);
|
RegisterSingleInstance(ServerApplicationPaths);
|
||||||
RegisterSingleInstance(taskManager);
|
RegisterSingleInstance(taskManager);
|
||||||
RegisterSingleInstance<IIsoManager>(new PismoIsoManager(Logger));
|
RegisterSingleInstance<IIsoManager>(new PismoIsoManager(Logger));
|
||||||
RegisterSingleInstance<IBlurayExaminer>(new BdInfoExaminer());
|
RegisterSingleInstance<IBlurayExaminer>(new BdInfoExaminer());
|
||||||
RegisterSingleInstance<IHttpClient>(new HttpManager(_applicationPaths, Logger));
|
RegisterSingleInstance<IHttpClient>(new HttpManager(ApplicationPaths, Logger));
|
||||||
RegisterSingleInstance<IZipClient>(new DotNetZipClient());
|
RegisterSingleInstance<IZipClient>(new DotNetZipClient());
|
||||||
RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger));
|
RegisterSingleInstance<IWebSocketServer>(() => new AlchemyServer(Logger));
|
||||||
RegisterSingleInstance(_jsonSerializer);
|
RegisterSingleInstance(_jsonSerializer);
|
||||||
|
@ -147,23 +153,11 @@ namespace MediaBrowser.ServerApplication
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Restarts this instance.
|
/// Restarts this instance.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <exception cref="System.NotImplementedException"></exception>
|
|
||||||
public void Restart()
|
public void Restart()
|
||||||
{
|
{
|
||||||
App.Instance.Restart();
|
App.Instance.Restart();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Reloads the logger.
|
|
||||||
/// </summary>
|
|
||||||
/// <exception cref="System.NotImplementedException"></exception>
|
|
||||||
public void ReloadLogger()
|
|
||||||
{
|
|
||||||
LogFilePath = Path.Combine(_applicationPaths.LogDirectoryPath, "Server-" + DateTime.Now.Ticks + ".log");
|
|
||||||
|
|
||||||
NlogManager.AddFileTarget(LogFilePath, Kernel.Configuration.EnableDebugLevelLogging);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether this instance can self update.
|
/// Gets or sets a value indicating whether this instance can self update.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -204,7 +198,7 @@ namespace MediaBrowser.ServerApplication
|
||||||
// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
|
// Gets all plugin assemblies by first reading all bytes of the .dll and calling Assembly.Load against that
|
||||||
// This will prevent the .dll file from getting locked, and allow us to replace it when needed
|
// This will prevent the .dll file from getting locked, and allow us to replace it when needed
|
||||||
foreach (var pluginAssembly in Directory
|
foreach (var pluginAssembly in Directory
|
||||||
.EnumerateFiles(_applicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
|
.EnumerateFiles(ApplicationPaths.PluginsPath, "*.dll", SearchOption.TopDirectoryOnly)
|
||||||
.Select(LoadAssembly).Where(a => a != null))
|
.Select(LoadAssembly).Where(a => a != null))
|
||||||
{
|
{
|
||||||
yield return pluginAssembly;
|
yield return pluginAssembly;
|
||||||
|
|
|
@ -55,6 +55,11 @@ namespace MediaBrowser.ServerApplication
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private readonly IApplicationHost _appHost;
|
private readonly IApplicationHost _appHost;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The _log manager
|
||||||
|
/// </summary>
|
||||||
|
private readonly ILogManager _logManager;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="MainWindow" /> class.
|
/// Initializes a new instance of the <see cref="MainWindow" /> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -62,20 +67,21 @@ namespace MediaBrowser.ServerApplication
|
||||||
/// <param name="logger">The logger.</param>
|
/// <param name="logger">The logger.</param>
|
||||||
/// <param name="appHost">The app host.</param>
|
/// <param name="appHost">The app host.</param>
|
||||||
/// <exception cref="System.ArgumentNullException">logger</exception>
|
/// <exception cref="System.ArgumentNullException">logger</exception>
|
||||||
public MainWindow(IJsonSerializer jsonSerializer, ILogger logger, IApplicationHost appHost)
|
public MainWindow(IJsonSerializer jsonSerializer, ILogManager logManager, IApplicationHost appHost)
|
||||||
{
|
{
|
||||||
if (jsonSerializer == null)
|
if (jsonSerializer == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("jsonSerializer");
|
throw new ArgumentNullException("jsonSerializer");
|
||||||
}
|
}
|
||||||
if (logger == null)
|
if (logManager == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("logger");
|
throw new ArgumentNullException("logManager");
|
||||||
}
|
}
|
||||||
|
|
||||||
_jsonSerializer = jsonSerializer;
|
_jsonSerializer = jsonSerializer;
|
||||||
_logger = logger;
|
_logger = logManager.GetLogger("MainWindow");
|
||||||
_appHost = appHost;
|
_appHost = appHost;
|
||||||
|
_logManager = logManager;
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
|
@ -94,7 +100,7 @@ namespace MediaBrowser.ServerApplication
|
||||||
Instance_ConfigurationUpdated(null, EventArgs.Empty);
|
Instance_ConfigurationUpdated(null, EventArgs.Empty);
|
||||||
|
|
||||||
Kernel.Instance.ReloadCompleted += KernelReloadCompleted;
|
Kernel.Instance.ReloadCompleted += KernelReloadCompleted;
|
||||||
Kernel.Instance.LoggerLoaded += LoadLogWindow;
|
_logManager.LoggerLoaded += LoadLogWindow;
|
||||||
Kernel.Instance.HasPendingRestartChanged += Instance_HasPendingRestartChanged;
|
Kernel.Instance.HasPendingRestartChanged += Instance_HasPendingRestartChanged;
|
||||||
Kernel.Instance.ConfigurationUpdated += Instance_ConfigurationUpdated;
|
Kernel.Instance.ConfigurationUpdated += Instance_ConfigurationUpdated;
|
||||||
}
|
}
|
||||||
|
@ -115,6 +121,13 @@ namespace MediaBrowser.ServerApplication
|
||||||
separatorDeveloperTools.Visibility = developerToolsVisibility;
|
separatorDeveloperTools.Visibility = developerToolsVisibility;
|
||||||
cmdReloadServer.Visibility = developerToolsVisibility;
|
cmdReloadServer.Visibility = developerToolsVisibility;
|
||||||
cmOpenExplorer.Visibility = developerToolsVisibility;
|
cmOpenExplorer.Visibility = developerToolsVisibility;
|
||||||
|
|
||||||
|
var logWindow = App.Instance.Windows.OfType<LogWindow>().FirstOrDefault();
|
||||||
|
|
||||||
|
if ((logWindow == null && Kernel.Instance.Configuration.ShowLogWindow) || (logWindow != null && !Kernel.Instance.Configuration.ShowLogWindow))
|
||||||
|
{
|
||||||
|
_logManager.ReloadLogger(Kernel.Instance.Configuration.EnableDebugLevelLogging ? LogSeverity.Debug : LogSeverity.Info);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user