From 48f81180726df5a0ef6a64572a4277f3c6af6f9c Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Fri, 28 Feb 2020 23:28:15 +0100 Subject: Do not save a reference to the startup config in ApplicationHost --- Emby.Server.Implementations/ApplicationHost.cs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8ea188724..f3abf2a3e 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -328,8 +328,6 @@ namespace Emby.Server.Implementations private IMediaSourceManager MediaSourceManager { get; set; } - private readonly IConfiguration _configuration; - /// /// Gets the installation manager. /// @@ -367,11 +365,8 @@ namespace Emby.Server.Implementations IStartupOptions options, IFileSystem fileSystem, IImageEncoder imageEncoder, - INetworkManager networkManager, - IConfiguration configuration) + INetworkManager networkManager) { - _configuration = configuration; - XmlSerializer = new MyXmlSerializer(); NetworkManager = networkManager; @@ -587,7 +582,8 @@ namespace Emby.Server.Implementations } } - public async Task InitAsync(IServiceCollection serviceCollection) + /// + public async Task InitAsync(IServiceCollection serviceCollection, IConfiguration startupConfig) { HttpPort = ServerConfigurationManager.Configuration.HttpServerPortNumber; HttpsPort = ServerConfigurationManager.Configuration.HttpsPortNumber; @@ -620,7 +616,7 @@ namespace Emby.Server.Implementations DiscoverTypes(); - await RegisterResources(serviceCollection).ConfigureAwait(false); + await RegisterResources(serviceCollection, startupConfig).ConfigureAwait(false); ContentRoot = ServerConfigurationManager.Configuration.DashboardSourcePath; if (string.IsNullOrEmpty(ContentRoot)) @@ -659,7 +655,7 @@ namespace Emby.Server.Implementations /// /// Registers resources that classes will depend on /// - protected async Task RegisterResources(IServiceCollection serviceCollection) + protected async Task RegisterResources(IServiceCollection serviceCollection, IConfiguration startupConfig) { serviceCollection.AddMemoryCache(); @@ -762,7 +758,7 @@ namespace Emby.Server.Implementations ProcessFactory, LocalizationManager, () => SubtitleEncoder, - _configuration, + startupConfig, StartupOptions.FFmpegPath); serviceCollection.AddSingleton(MediaEncoder); @@ -784,7 +780,7 @@ namespace Emby.Server.Implementations this, LoggerFactory.CreateLogger(), ServerConfigurationManager, - _configuration, + startupConfig, NetworkManager, JsonSerializer, XmlSerializer, -- cgit v1.2.3 From 189f005846af9a8f960f6a79cecc8a65feb0bfa6 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Fri, 28 Feb 2020 23:35:53 +0100 Subject: Remove IConfiguration from service collection This does not appear to be used anywhere and the web host already handles injecting this as a special case anyways --- Emby.Server.Implementations/ApplicationHost.cs | 2 -- 1 file changed, 2 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index f3abf2a3e..eee32520f 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -664,8 +664,6 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(ApplicationPaths); - serviceCollection.AddSingleton(_configuration); - serviceCollection.AddSingleton(JsonSerializer); serviceCollection.AddSingleton(LoggerFactory); -- cgit v1.2.3 From c376f4ca51b55db4dff8d5aa50b7a847870e41f5 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 3 Mar 2020 00:35:41 +0100 Subject: Register Serilog logging services correctly --- Emby.Server.Implementations/ApplicationHost.cs | 5 ++--- Jellyfin.Server/Program.cs | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 8ea188724..1e7bbd704 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -672,9 +672,8 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(JsonSerializer); - serviceCollection.AddSingleton(LoggerFactory); - serviceCollection.AddLogging(); - serviceCollection.AddSingleton(Logger); + // TODO: Support for injecting ILogger should be deprecated in favour of ILogger and this removed + serviceCollection.AddSingleton(_logger); serviceCollection.AddSingleton(FileSystemManager); serviceCollection.AddSingleton(); diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index 1dd598236..484e507a2 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -26,6 +26,7 @@ using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Serilog; +using Serilog.Events; using Serilog.Extensions.Logging; using SQLitePCL; using ILogger = Microsoft.Extensions.Logging.ILogger; @@ -260,6 +261,7 @@ namespace Jellyfin.Server } } }) + .UseSerilog() .UseContentRoot(appHost.ContentRoot) .ConfigureServices(services => { -- cgit v1.2.3 From a4bf645ba5f878f23ce2ba916121fddd6b981968 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 3 Mar 2020 01:10:26 +0100 Subject: Fix compilation error --- Emby.Server.Implementations/ApplicationHost.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 1e7bbd704..679ef4851 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -673,7 +673,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(JsonSerializer); // TODO: Support for injecting ILogger should be deprecated in favour of ILogger and this removed - serviceCollection.AddSingleton(_logger); + serviceCollection.AddSingleton(Logger); serviceCollection.AddSingleton(FileSystemManager); serviceCollection.AddSingleton(); -- cgit v1.2.3 From 370c312e01f25b4da53f8ca9ecde6d90ed1fad59 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 3 Mar 2020 23:07:33 +0100 Subject: Make logger private in ApplicationHost --- Emby.Server.Implementations/ApplicationHost.cs | 77 ++++++++++++-------------- 1 file changed, 36 insertions(+), 41 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 679ef4851..71cff80af 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -166,12 +166,7 @@ namespace Emby.Server.Implementations /// public bool IsShuttingDown { get; private set; } - /// - /// Gets or sets the logger. - /// - /// The logger. - protected ILogger Logger { get; set; } - + private ILogger _logger; private IPlugin[] _plugins; /// @@ -383,7 +378,7 @@ namespace Emby.Server.Implementations ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager); - Logger = LoggerFactory.CreateLogger("App"); + _logger = LoggerFactory.CreateLogger("App"); StartupOptions = options; @@ -490,12 +485,12 @@ namespace Emby.Server.Implementations { try { - Logger.LogDebug("Creating instance of {Type}", type); + _logger.LogDebug("Creating instance of {Type}", type); return ActivatorUtilities.CreateInstance(ServiceProvider, type); } catch (Exception ex) { - Logger.LogError(ex, "Error creating {Type}", type); + _logger.LogError(ex, "Error creating {Type}", type); return null; } } @@ -546,7 +541,7 @@ namespace Emby.Server.Implementations /// . public async Task RunStartupTasksAsync() { - Logger.LogInformation("Running startup tasks"); + _logger.LogInformation("Running startup tasks"); Resolve().AddTasks(GetExports(false)); @@ -554,21 +549,21 @@ namespace Emby.Server.Implementations MediaEncoder.SetFFmpegPath(); - Logger.LogInformation("ServerId: {0}", SystemId); + _logger.LogInformation("ServerId: {0}", SystemId); var entryPoints = GetExports(); var stopWatch = new Stopwatch(); stopWatch.Start(); await Task.WhenAll(StartEntryPoints(entryPoints, true)).ConfigureAwait(false); - Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed); + _logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed); - Logger.LogInformation("Core startup complete"); + _logger.LogInformation("Core startup complete"); HttpServer.GlobalResponse = null; stopWatch.Restart(); await Task.WhenAll(StartEntryPoints(entryPoints, false)).ConfigureAwait(false); - Logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed); + _logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed); stopWatch.Stop(); } @@ -581,7 +576,7 @@ namespace Emby.Server.Implementations continue; } - Logger.LogDebug("Starting entry point {Type}", entryPoint.GetType()); + _logger.LogDebug("Starting entry point {Type}", entryPoint.GetType()); yield return entryPoint.RunAsync(); } @@ -615,7 +610,7 @@ namespace Emby.Server.Implementations plugin.Version)); } - Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString()); + _logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString()); } DiscoverTypes(); @@ -652,7 +647,7 @@ namespace Emby.Server.Implementations var response = context.Response; var localPath = context.Request.Path.ToString(); - var req = new WebSocketSharpRequest(request, response, request.Path, Logger); + var req = new WebSocketSharpRequest(request, response, request.Path, _logger); await HttpServer.RequestHandler(req, request.GetDisplayUrl(), request.Host.ToString(), localPath, context.RequestAborted).ConfigureAwait(false); } @@ -673,7 +668,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(JsonSerializer); // TODO: Support for injecting ILogger should be deprecated in favour of ILogger and this removed - serviceCollection.AddSingleton(Logger); + serviceCollection.AddSingleton(_logger); serviceCollection.AddSingleton(FileSystemManager); serviceCollection.AddSingleton(); @@ -941,7 +936,7 @@ namespace Emby.Server.Implementations // localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA; if (!localCert.HasPrivateKey) { - Logger.LogError("No private key included in SSL cert {CertificateLocation}.", certificateLocation); + _logger.LogError("No private key included in SSL cert {CertificateLocation}.", certificateLocation); return null; } @@ -949,7 +944,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error loading cert from {CertificateLocation}", certificateLocation); + _logger.LogError(ex, "Error loading cert from {CertificateLocation}", certificateLocation); return null; } } @@ -1128,7 +1123,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error getting plugin Id from {PluginName}.", plugin.GetType().FullName); + _logger.LogError(ex, "Error getting plugin Id from {PluginName}.", plugin.GetType().FullName); } } @@ -1139,7 +1134,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error loading plugin {PluginName}", plugin.GetType().FullName); + _logger.LogError(ex, "Error loading plugin {PluginName}", plugin.GetType().FullName); return null; } @@ -1151,7 +1146,7 @@ namespace Emby.Server.Implementations /// protected void DiscoverTypes() { - Logger.LogInformation("Loading assemblies"); + _logger.LogInformation("Loading assemblies"); _allConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray(); } @@ -1167,7 +1162,7 @@ namespace Emby.Server.Implementations } catch (TypeLoadException ex) { - Logger.LogError(ex, "Error getting exported types from {Assembly}", ass.FullName); + _logger.LogError(ex, "Error getting exported types from {Assembly}", ass.FullName); continue; } @@ -1205,7 +1200,7 @@ namespace Emby.Server.Implementations }); } - protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(Logger); + protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(_logger); private CertificateInfo GetCertificateInfo(bool generateCertificate) { @@ -1259,7 +1254,7 @@ namespace Emby.Server.Implementations if (requiresRestart) { - Logger.LogInformation("App needs to be restarted due to configuration change."); + _logger.LogInformation("App needs to be restarted due to configuration change."); NotifyPendingRestart(); } @@ -1270,7 +1265,7 @@ namespace Emby.Server.Implementations /// public void NotifyPendingRestart() { - Logger.LogInformation("App needs to be restarted."); + _logger.LogInformation("App needs to be restarted."); var changed = !HasPendingRestart; @@ -1278,7 +1273,7 @@ namespace Emby.Server.Implementations if (changed) { - EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, Logger); + EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, _logger); } } @@ -1307,10 +1302,10 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error sending server restart notification"); + _logger.LogError(ex, "Error sending server restart notification"); } - Logger.LogInformation("Calling RestartInternal"); + _logger.LogInformation("Calling RestartInternal"); RestartInternal(); }); @@ -1335,11 +1330,11 @@ namespace Emby.Server.Implementations } catch (FileLoadException ex) { - Logger.LogError(ex, "Failed to load assembly {Path}", file); + _logger.LogError(ex, "Failed to load assembly {Path}", file); continue; } - Logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugAss.FullName, file); + _logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugAss.FullName, file); yield return plugAss; } } @@ -1474,7 +1469,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error getting local Ip address information"); + _logger.LogError(ex, "Error getting local Ip address information"); } return null; @@ -1637,19 +1632,19 @@ namespace Emby.Server.Implementations var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase); _validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid); - Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid); + _logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid); return valid; } } } catch (OperationCanceledException) { - Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled"); + _logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled"); throw; } catch (Exception ex) { - Logger.LogDebug(ex, "Ping test result to {0}. Success: {1}", apiUrl, false); + _logger.LogDebug(ex, "Ping test result to {0}. Success: {1}", apiUrl, false); _validAddressResults.AddOrUpdate(apiUrl, false, (k, v) => false); return false; @@ -1679,7 +1674,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error sending server shutdown notification"); + _logger.LogError(ex, "Error sending server shutdown notification"); } ShutdownInternal(); @@ -1741,7 +1736,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error launching url: {url}", url); + _logger.LogError(ex, "Error launching url: {url}", url); throw; } } @@ -1781,14 +1776,14 @@ namespace Emby.Server.Implementations { var type = GetType(); - Logger.LogInformation("Disposing {Type}", type.Name); + _logger.LogInformation("Disposing {Type}", type.Name); var parts = _disposableParts.Distinct().Where(i => i.GetType() != type).ToList(); _disposableParts.Clear(); foreach (var part in parts) { - Logger.LogInformation("Disposing {Type}", part.GetType().Name); + _logger.LogInformation("Disposing {Type}", part.GetType().Name); try { @@ -1796,7 +1791,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - Logger.LogError(ex, "Error disposing {Type}", part.GetType().Name); + _logger.LogError(ex, "Error disposing {Type}", part.GetType().Name); } } -- cgit v1.2.3 From c49a12dd73541c588e22ff558436652c188badb2 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 3 Mar 2020 23:31:25 +0100 Subject: Make LoggerFactory private in ApplicationHost and use it to construct loggers with context --- Emby.Server.Implementations/ApplicationHost.cs | 90 ++++++++++------------ .../SocketSharp/WebSocketSharpListener.cs | 5 +- 2 files changed, 44 insertions(+), 51 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 71cff80af..9b478772c 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -118,8 +118,10 @@ namespace Emby.Server.Implementations /// public abstract class ApplicationHost : IServerApplicationHost, IDisposable { - private SqliteUserRepository _userRepository; + private readonly ILoggerFactory _loggerFactory; + private readonly ILogger _logger; + private SqliteUserRepository _userRepository; private SqliteDisplayPreferencesRepository _displayPreferencesRepository; /// @@ -166,7 +168,6 @@ namespace Emby.Server.Implementations /// public bool IsShuttingDown { get; private set; } - private ILogger _logger; private IPlugin[] _plugins; /// @@ -175,12 +176,6 @@ namespace Emby.Server.Implementations /// The plugins. public IReadOnlyList Plugins => _plugins; - /// - /// Gets or sets the logger factory. - /// - /// The logger factory. - public ILoggerFactory LoggerFactory { get; protected set; } - /// /// Gets or sets the application paths. /// @@ -365,6 +360,8 @@ namespace Emby.Server.Implementations INetworkManager networkManager, IConfiguration configuration) { + _loggerFactory = loggerFactory; + _logger = _loggerFactory.CreateLogger("App"); _configuration = configuration; XmlSerializer = new MyXmlSerializer(); @@ -373,12 +370,9 @@ namespace Emby.Server.Implementations networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets; ApplicationPaths = applicationPaths; - LoggerFactory = loggerFactory; FileSystemManager = fileSystem; - ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager); - - _logger = LoggerFactory.CreateLogger("App"); + ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, _loggerFactory, XmlSerializer, FileSystemManager); StartupOptions = options; @@ -447,7 +441,7 @@ namespace Emby.Server.Implementations { if (_deviceId == null) { - _deviceId = new DeviceId(ApplicationPaths, LoggerFactory); + _deviceId = new DeviceId(ApplicationPaths, _loggerFactory); } return _deviceId.Value; @@ -647,7 +641,7 @@ namespace Emby.Server.Implementations var response = context.Response; var localPath = context.Request.Path.ToString(); - var req = new WebSocketSharpRequest(request, response, request.Path, _logger); + var req = new WebSocketSharpRequest(request, response, request.Path, _loggerFactory.CreateLogger()); await HttpServer.RequestHandler(req, request.GetDisplayUrl(), request.Host.ToString(), localPath, context.RequestAborted).ConfigureAwait(false); } @@ -675,7 +669,7 @@ namespace Emby.Server.Implementations HttpClient = new HttpClientManager.HttpClientManager( ApplicationPaths, - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), FileSystemManager, () => ApplicationUserAgent); serviceCollection.AddSingleton(HttpClient); @@ -685,7 +679,7 @@ namespace Emby.Server.Implementations IsoManager = new IsoManager(); serviceCollection.AddSingleton(IsoManager); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, _loggerFactory, FileSystemManager); serviceCollection.AddSingleton(TaskManager); serviceCollection.AddSingleton(XmlSerializer); @@ -712,22 +706,22 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(ServerConfigurationManager); - LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, LoggerFactory.CreateLogger()); + LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, _loggerFactory.CreateLogger()); await LocalizationManager.LoadAll().ConfigureAwait(false); serviceCollection.AddSingleton(LocalizationManager); serviceCollection.AddSingleton(new BdInfoExaminer(FileSystemManager)); - UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager); + UserDataManager = new UserDataManager(_loggerFactory, ServerConfigurationManager, () => UserManager); serviceCollection.AddSingleton(UserDataManager); _displayPreferencesRepository = new SqliteDisplayPreferencesRepository( - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), ApplicationPaths, FileSystemManager); serviceCollection.AddSingleton(_displayPreferencesRepository); - ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, LoggerFactory.CreateLogger(), LocalizationManager); + ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, _loggerFactory.CreateLogger(), LocalizationManager); serviceCollection.AddSingleton(ItemRepository); AuthenticationRepository = GetAuthenticationRepository(); @@ -736,7 +730,7 @@ namespace Emby.Server.Implementations _userRepository = GetUserRepository(); UserManager = new UserManager( - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), _userRepository, XmlSerializer, NetworkManager, @@ -750,7 +744,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(UserManager); MediaEncoder = new MediaBrowser.MediaEncoding.Encoder.MediaEncoder( - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), ServerConfigurationManager, FileSystemManager, ProcessFactory, @@ -760,23 +754,23 @@ namespace Emby.Server.Implementations StartupOptions.FFmpegPath); serviceCollection.AddSingleton(MediaEncoder); - LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager, MediaEncoder); + LibraryManager = new LibraryManager(this, _loggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager, MediaEncoder); serviceCollection.AddSingleton(LibraryManager); var musicManager = new MusicManager(LibraryManager); serviceCollection.AddSingleton(musicManager); - LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager); + LibraryMonitor = new LibraryMonitor(_loggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager); serviceCollection.AddSingleton(LibraryMonitor); - serviceCollection.AddSingleton(new SearchEngine(LoggerFactory, LibraryManager, UserManager)); + serviceCollection.AddSingleton(new SearchEngine(_loggerFactory, LibraryManager, UserManager)); CertificateInfo = GetCertificateInfo(true); Certificate = GetCertificate(CertificateInfo); HttpServer = new HttpListenerHost( this, - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), ServerConfigurationManager, _configuration, NetworkManager, @@ -789,7 +783,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(HttpServer); - ImageProcessor = new ImageProcessor(LoggerFactory.CreateLogger(), ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder); + ImageProcessor = new ImageProcessor(_loggerFactory.CreateLogger(), ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder); serviceCollection.AddSingleton(ImageProcessor); TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager, ServerConfigurationManager); @@ -798,23 +792,23 @@ namespace Emby.Server.Implementations DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager); serviceCollection.AddSingleton(DeviceManager); - MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder); + MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, _loggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder); serviceCollection.AddSingleton(MediaSourceManager); - SubtitleManager = new SubtitleManager(LoggerFactory, FileSystemManager, LibraryMonitor, MediaSourceManager, LocalizationManager); + SubtitleManager = new SubtitleManager(_loggerFactory, FileSystemManager, LibraryMonitor, MediaSourceManager, LocalizationManager); serviceCollection.AddSingleton(SubtitleManager); - ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LoggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); + ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, _loggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); serviceCollection.AddSingleton(ProviderManager); - DtoService = new DtoService(LoggerFactory, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ProviderManager, this, () => MediaSourceManager, () => LiveTvManager); + DtoService = new DtoService(_loggerFactory, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ProviderManager, this, () => MediaSourceManager, () => LiveTvManager); serviceCollection.AddSingleton(DtoService); - ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LoggerFactory, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, ProviderManager); + ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, _loggerFactory, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, ProviderManager); serviceCollection.AddSingleton(ChannelManager); SessionManager = new SessionManager( - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), UserDataManager, LibraryManager, UserManager, @@ -828,47 +822,47 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(SessionManager); serviceCollection.AddSingleton( - new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LoggerFactory, JsonSerializer, this)); + new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, _loggerFactory, JsonSerializer, this)); - CollectionManager = new CollectionManager(LibraryManager, ApplicationPaths, LocalizationManager, FileSystemManager, LibraryMonitor, LoggerFactory, ProviderManager); + CollectionManager = new CollectionManager(LibraryManager, ApplicationPaths, LocalizationManager, FileSystemManager, LibraryMonitor, _loggerFactory, ProviderManager); serviceCollection.AddSingleton(CollectionManager); serviceCollection.AddSingleton(typeof(IPlaylistManager), typeof(PlaylistManager)); - LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, LoggerFactory, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, FileSystemManager, () => ChannelManager); + LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, _loggerFactory, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, FileSystemManager, () => ChannelManager); serviceCollection.AddSingleton(LiveTvManager); UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, UserManager, ChannelManager, LiveTvManager, ServerConfigurationManager); serviceCollection.AddSingleton(UserViewManager); NotificationManager = new NotificationManager( - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), UserManager, ServerConfigurationManager); serviceCollection.AddSingleton(NotificationManager); serviceCollection.AddSingleton(new DeviceDiscovery(ServerConfigurationManager)); - ChapterManager = new ChapterManager(LibraryManager, LoggerFactory, ServerConfigurationManager, ItemRepository); + ChapterManager = new ChapterManager(LibraryManager, _loggerFactory, ServerConfigurationManager, ItemRepository); serviceCollection.AddSingleton(ChapterManager); - EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, LoggerFactory, MediaEncoder, ChapterManager, LibraryManager); + EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, _loggerFactory, MediaEncoder, ChapterManager, LibraryManager); serviceCollection.AddSingleton(EncodingManager); var activityLogRepo = GetActivityLogRepository(); serviceCollection.AddSingleton(activityLogRepo); - serviceCollection.AddSingleton(new ActivityManager(LoggerFactory, activityLogRepo, UserManager)); + serviceCollection.AddSingleton(new ActivityManager(_loggerFactory, activityLogRepo, UserManager)); var authContext = new AuthorizationContext(AuthenticationRepository, UserManager); serviceCollection.AddSingleton(authContext); serviceCollection.AddSingleton(new SessionContext(UserManager, authContext, SessionManager)); - AuthService = new AuthService(LoggerFactory.CreateLogger(), authContext, ServerConfigurationManager, SessionManager, NetworkManager); + AuthService = new AuthService(_loggerFactory.CreateLogger(), authContext, ServerConfigurationManager, SessionManager, NetworkManager); serviceCollection.AddSingleton(AuthService); SubtitleEncoder = new MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder( LibraryManager, - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), ApplicationPaths, FileSystemManager, MediaEncoder, @@ -884,7 +878,7 @@ namespace Emby.Server.Implementations _displayPreferencesRepository.Initialize(); - var userDataRepo = new SqliteUserDataRepository(LoggerFactory.CreateLogger(), ApplicationPaths); + var userDataRepo = new SqliteUserDataRepository(_loggerFactory.CreateLogger(), ApplicationPaths); SetStaticProperties(); @@ -956,7 +950,7 @@ namespace Emby.Server.Implementations private SqliteUserRepository GetUserRepository() { var repo = new SqliteUserRepository( - LoggerFactory.CreateLogger(), + _loggerFactory.CreateLogger(), ApplicationPaths); repo.Initialize(); @@ -966,7 +960,7 @@ namespace Emby.Server.Implementations private IAuthenticationRepository GetAuthenticationRepository() { - var repo = new AuthenticationRepository(LoggerFactory, ServerConfigurationManager); + var repo = new AuthenticationRepository(_loggerFactory, ServerConfigurationManager); repo.Initialize(); @@ -975,7 +969,7 @@ namespace Emby.Server.Implementations private IActivityRepository GetActivityLogRepository() { - var repo = new ActivityRepository(LoggerFactory, ServerConfigurationManager.ApplicationPaths, FileSystemManager); + var repo = new ActivityRepository(_loggerFactory, ServerConfigurationManager.ApplicationPaths, FileSystemManager); repo.Initialize(); @@ -990,7 +984,7 @@ namespace Emby.Server.Implementations ItemRepository.ImageProcessor = ImageProcessor; // For now there's no real way to inject these properly - BaseItem.Logger = LoggerFactory.CreateLogger("BaseItem"); + BaseItem.Logger = _loggerFactory.CreateLogger("BaseItem"); BaseItem.ConfigurationManager = ServerConfigurationManager; BaseItem.LibraryManager = LibraryManager; BaseItem.ProviderManager = ProviderManager; @@ -1200,7 +1194,7 @@ namespace Emby.Server.Implementations }); } - protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(_logger); + protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(_loggerFactory.CreateLogger()); private CertificateInfo GetCertificateInfo(bool generateCertificate) { diff --git a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs index 2e12a19fd..b85750c9b 100644 --- a/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs +++ b/Emby.Server.Implementations/SocketSharp/WebSocketSharpListener.cs @@ -21,15 +21,14 @@ namespace Emby.Server.Implementations.SocketSharp private CancellationTokenSource _disposeCancellationTokenSource = new CancellationTokenSource(); private CancellationToken _disposeCancellationToken; - public WebSocketSharpListener( - ILogger logger) + public WebSocketSharpListener(ILogger logger) { _logger = logger; - _disposeCancellationToken = _disposeCancellationTokenSource.Token; } public Func ErrorHandler { get; set; } + public Func RequestHandler { get; set; } public Action WebSocketConnected { get; set; } -- cgit v1.2.3 From 6b06a9a91937961eaf0cac610a96a6dd06f678c7 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 3 Mar 2020 23:53:48 +0100 Subject: Make Logger and LoggerFactory both protected in ApplicationHost --- Emby.Server.Implementations/ApplicationHost.cs | 155 +++++++++++++------------ 1 file changed, 81 insertions(+), 74 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 9b478772c..78b65e798 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -118,9 +118,6 @@ namespace Emby.Server.Implementations /// public abstract class ApplicationHost : IServerApplicationHost, IDisposable { - private readonly ILoggerFactory _loggerFactory; - private readonly ILogger _logger; - private SqliteUserRepository _userRepository; private SqliteDisplayPreferencesRepository _displayPreferencesRepository; @@ -168,6 +165,16 @@ namespace Emby.Server.Implementations /// public bool IsShuttingDown { get; private set; } + /// + /// Gets the logger factory. + /// + protected ILoggerFactory LoggerFactory { get; } + + /// + /// Gets the logger. + /// + protected ILogger Logger { get; } + private IPlugin[] _plugins; /// @@ -360,8 +367,6 @@ namespace Emby.Server.Implementations INetworkManager networkManager, IConfiguration configuration) { - _loggerFactory = loggerFactory; - _logger = _loggerFactory.CreateLogger("App"); _configuration = configuration; XmlSerializer = new MyXmlSerializer(); @@ -370,9 +375,11 @@ namespace Emby.Server.Implementations networkManager.LocalSubnetsFn = GetConfiguredLocalSubnets; ApplicationPaths = applicationPaths; + LoggerFactory = loggerFactory; FileSystemManager = fileSystem; - ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, _loggerFactory, XmlSerializer, FileSystemManager); + Logger = LoggerFactory.CreateLogger("App"); + ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager); StartupOptions = options; @@ -441,7 +448,7 @@ namespace Emby.Server.Implementations { if (_deviceId == null) { - _deviceId = new DeviceId(ApplicationPaths, _loggerFactory); + _deviceId = new DeviceId(ApplicationPaths, LoggerFactory); } return _deviceId.Value; @@ -479,12 +486,12 @@ namespace Emby.Server.Implementations { try { - _logger.LogDebug("Creating instance of {Type}", type); + Logger.LogDebug("Creating instance of {Type}", type); return ActivatorUtilities.CreateInstance(ServiceProvider, type); } catch (Exception ex) { - _logger.LogError(ex, "Error creating {Type}", type); + Logger.LogError(ex, "Error creating {Type}", type); return null; } } @@ -535,7 +542,7 @@ namespace Emby.Server.Implementations /// . public async Task RunStartupTasksAsync() { - _logger.LogInformation("Running startup tasks"); + Logger.LogInformation("Running startup tasks"); Resolve().AddTasks(GetExports(false)); @@ -543,21 +550,21 @@ namespace Emby.Server.Implementations MediaEncoder.SetFFmpegPath(); - _logger.LogInformation("ServerId: {0}", SystemId); + Logger.LogInformation("ServerId: {0}", SystemId); var entryPoints = GetExports(); var stopWatch = new Stopwatch(); stopWatch.Start(); await Task.WhenAll(StartEntryPoints(entryPoints, true)).ConfigureAwait(false); - _logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed); + Logger.LogInformation("Executed all pre-startup entry points in {Elapsed:g}", stopWatch.Elapsed); - _logger.LogInformation("Core startup complete"); + Logger.LogInformation("Core startup complete"); HttpServer.GlobalResponse = null; stopWatch.Restart(); await Task.WhenAll(StartEntryPoints(entryPoints, false)).ConfigureAwait(false); - _logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed); + Logger.LogInformation("Executed all post-startup entry points in {Elapsed:g}", stopWatch.Elapsed); stopWatch.Stop(); } @@ -570,7 +577,7 @@ namespace Emby.Server.Implementations continue; } - _logger.LogDebug("Starting entry point {Type}", entryPoint.GetType()); + Logger.LogDebug("Starting entry point {Type}", entryPoint.GetType()); yield return entryPoint.RunAsync(); } @@ -604,7 +611,7 @@ namespace Emby.Server.Implementations plugin.Version)); } - _logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString()); + Logger.LogInformation("Plugins: {Plugins}", pluginBuilder.ToString()); } DiscoverTypes(); @@ -641,7 +648,7 @@ namespace Emby.Server.Implementations var response = context.Response; var localPath = context.Request.Path.ToString(); - var req = new WebSocketSharpRequest(request, response, request.Path, _loggerFactory.CreateLogger()); + var req = new WebSocketSharpRequest(request, response, request.Path, LoggerFactory.CreateLogger()); await HttpServer.RequestHandler(req, request.GetDisplayUrl(), request.Host.ToString(), localPath, context.RequestAborted).ConfigureAwait(false); } @@ -662,14 +669,14 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(JsonSerializer); // TODO: Support for injecting ILogger should be deprecated in favour of ILogger and this removed - serviceCollection.AddSingleton(_logger); + serviceCollection.AddSingleton(Logger); serviceCollection.AddSingleton(FileSystemManager); serviceCollection.AddSingleton(); HttpClient = new HttpClientManager.HttpClientManager( ApplicationPaths, - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), FileSystemManager, () => ApplicationUserAgent); serviceCollection.AddSingleton(HttpClient); @@ -679,7 +686,7 @@ namespace Emby.Server.Implementations IsoManager = new IsoManager(); serviceCollection.AddSingleton(IsoManager); - TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, _loggerFactory, FileSystemManager); + TaskManager = new TaskManager(ApplicationPaths, JsonSerializer, LoggerFactory, FileSystemManager); serviceCollection.AddSingleton(TaskManager); serviceCollection.AddSingleton(XmlSerializer); @@ -706,22 +713,22 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(ServerConfigurationManager); - LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, _loggerFactory.CreateLogger()); + LocalizationManager = new LocalizationManager(ServerConfigurationManager, JsonSerializer, LoggerFactory.CreateLogger()); await LocalizationManager.LoadAll().ConfigureAwait(false); serviceCollection.AddSingleton(LocalizationManager); serviceCollection.AddSingleton(new BdInfoExaminer(FileSystemManager)); - UserDataManager = new UserDataManager(_loggerFactory, ServerConfigurationManager, () => UserManager); + UserDataManager = new UserDataManager(LoggerFactory, ServerConfigurationManager, () => UserManager); serviceCollection.AddSingleton(UserDataManager); _displayPreferencesRepository = new SqliteDisplayPreferencesRepository( - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), ApplicationPaths, FileSystemManager); serviceCollection.AddSingleton(_displayPreferencesRepository); - ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, _loggerFactory.CreateLogger(), LocalizationManager); + ItemRepository = new SqliteItemRepository(ServerConfigurationManager, this, LoggerFactory.CreateLogger(), LocalizationManager); serviceCollection.AddSingleton(ItemRepository); AuthenticationRepository = GetAuthenticationRepository(); @@ -730,7 +737,7 @@ namespace Emby.Server.Implementations _userRepository = GetUserRepository(); UserManager = new UserManager( - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), _userRepository, XmlSerializer, NetworkManager, @@ -744,7 +751,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(UserManager); MediaEncoder = new MediaBrowser.MediaEncoding.Encoder.MediaEncoder( - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), ServerConfigurationManager, FileSystemManager, ProcessFactory, @@ -754,23 +761,23 @@ namespace Emby.Server.Implementations StartupOptions.FFmpegPath); serviceCollection.AddSingleton(MediaEncoder); - LibraryManager = new LibraryManager(this, _loggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager, MediaEncoder); + LibraryManager = new LibraryManager(this, LoggerFactory, TaskManager, UserManager, ServerConfigurationManager, UserDataManager, () => LibraryMonitor, FileSystemManager, () => ProviderManager, () => UserViewManager, MediaEncoder); serviceCollection.AddSingleton(LibraryManager); var musicManager = new MusicManager(LibraryManager); serviceCollection.AddSingleton(musicManager); - LibraryMonitor = new LibraryMonitor(_loggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager); + LibraryMonitor = new LibraryMonitor(LoggerFactory, LibraryManager, ServerConfigurationManager, FileSystemManager); serviceCollection.AddSingleton(LibraryMonitor); - serviceCollection.AddSingleton(new SearchEngine(_loggerFactory, LibraryManager, UserManager)); + serviceCollection.AddSingleton(new SearchEngine(LoggerFactory, LibraryManager, UserManager)); CertificateInfo = GetCertificateInfo(true); Certificate = GetCertificate(CertificateInfo); HttpServer = new HttpListenerHost( this, - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), ServerConfigurationManager, _configuration, NetworkManager, @@ -783,7 +790,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(HttpServer); - ImageProcessor = new ImageProcessor(_loggerFactory.CreateLogger(), ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder); + ImageProcessor = new ImageProcessor(LoggerFactory.CreateLogger(), ServerConfigurationManager.ApplicationPaths, FileSystemManager, ImageEncoder, () => LibraryManager, () => MediaEncoder); serviceCollection.AddSingleton(ImageProcessor); TVSeriesManager = new TVSeriesManager(UserManager, UserDataManager, LibraryManager, ServerConfigurationManager); @@ -792,23 +799,23 @@ namespace Emby.Server.Implementations DeviceManager = new DeviceManager(AuthenticationRepository, JsonSerializer, LibraryManager, LocalizationManager, UserManager, FileSystemManager, LibraryMonitor, ServerConfigurationManager); serviceCollection.AddSingleton(DeviceManager); - MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, _loggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder); + MediaSourceManager = new MediaSourceManager(ItemRepository, ApplicationPaths, LocalizationManager, UserManager, LibraryManager, LoggerFactory, JsonSerializer, FileSystemManager, UserDataManager, () => MediaEncoder); serviceCollection.AddSingleton(MediaSourceManager); - SubtitleManager = new SubtitleManager(_loggerFactory, FileSystemManager, LibraryMonitor, MediaSourceManager, LocalizationManager); + SubtitleManager = new SubtitleManager(LoggerFactory, FileSystemManager, LibraryMonitor, MediaSourceManager, LocalizationManager); serviceCollection.AddSingleton(SubtitleManager); - ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, _loggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); + ProviderManager = new ProviderManager(HttpClient, SubtitleManager, ServerConfigurationManager, LibraryMonitor, LoggerFactory, FileSystemManager, ApplicationPaths, () => LibraryManager, JsonSerializer); serviceCollection.AddSingleton(ProviderManager); - DtoService = new DtoService(_loggerFactory, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ProviderManager, this, () => MediaSourceManager, () => LiveTvManager); + DtoService = new DtoService(LoggerFactory, LibraryManager, UserDataManager, ItemRepository, ImageProcessor, ProviderManager, this, () => MediaSourceManager, () => LiveTvManager); serviceCollection.AddSingleton(DtoService); - ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, _loggerFactory, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, ProviderManager); + ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LoggerFactory, ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, ProviderManager); serviceCollection.AddSingleton(ChannelManager); SessionManager = new SessionManager( - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), UserDataManager, LibraryManager, UserManager, @@ -822,47 +829,47 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton(SessionManager); serviceCollection.AddSingleton( - new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, _loggerFactory, JsonSerializer, this)); + new DlnaManager(XmlSerializer, FileSystemManager, ApplicationPaths, LoggerFactory, JsonSerializer, this)); - CollectionManager = new CollectionManager(LibraryManager, ApplicationPaths, LocalizationManager, FileSystemManager, LibraryMonitor, _loggerFactory, ProviderManager); + CollectionManager = new CollectionManager(LibraryManager, ApplicationPaths, LocalizationManager, FileSystemManager, LibraryMonitor, LoggerFactory, ProviderManager); serviceCollection.AddSingleton(CollectionManager); serviceCollection.AddSingleton(typeof(IPlaylistManager), typeof(PlaylistManager)); - LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, _loggerFactory, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, FileSystemManager, () => ChannelManager); + LiveTvManager = new LiveTvManager(this, ServerConfigurationManager, LoggerFactory, ItemRepository, ImageProcessor, UserDataManager, DtoService, UserManager, LibraryManager, TaskManager, LocalizationManager, JsonSerializer, FileSystemManager, () => ChannelManager); serviceCollection.AddSingleton(LiveTvManager); UserViewManager = new UserViewManager(LibraryManager, LocalizationManager, UserManager, ChannelManager, LiveTvManager, ServerConfigurationManager); serviceCollection.AddSingleton(UserViewManager); NotificationManager = new NotificationManager( - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), UserManager, ServerConfigurationManager); serviceCollection.AddSingleton(NotificationManager); serviceCollection.AddSingleton(new DeviceDiscovery(ServerConfigurationManager)); - ChapterManager = new ChapterManager(LibraryManager, _loggerFactory, ServerConfigurationManager, ItemRepository); + ChapterManager = new ChapterManager(LibraryManager, LoggerFactory, ServerConfigurationManager, ItemRepository); serviceCollection.AddSingleton(ChapterManager); - EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, _loggerFactory, MediaEncoder, ChapterManager, LibraryManager); + EncodingManager = new MediaEncoder.EncodingManager(FileSystemManager, LoggerFactory, MediaEncoder, ChapterManager, LibraryManager); serviceCollection.AddSingleton(EncodingManager); var activityLogRepo = GetActivityLogRepository(); serviceCollection.AddSingleton(activityLogRepo); - serviceCollection.AddSingleton(new ActivityManager(_loggerFactory, activityLogRepo, UserManager)); + serviceCollection.AddSingleton(new ActivityManager(LoggerFactory, activityLogRepo, UserManager)); var authContext = new AuthorizationContext(AuthenticationRepository, UserManager); serviceCollection.AddSingleton(authContext); serviceCollection.AddSingleton(new SessionContext(UserManager, authContext, SessionManager)); - AuthService = new AuthService(_loggerFactory.CreateLogger(), authContext, ServerConfigurationManager, SessionManager, NetworkManager); + AuthService = new AuthService(LoggerFactory.CreateLogger(), authContext, ServerConfigurationManager, SessionManager, NetworkManager); serviceCollection.AddSingleton(AuthService); SubtitleEncoder = new MediaBrowser.MediaEncoding.Subtitles.SubtitleEncoder( LibraryManager, - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), ApplicationPaths, FileSystemManager, MediaEncoder, @@ -878,7 +885,7 @@ namespace Emby.Server.Implementations _displayPreferencesRepository.Initialize(); - var userDataRepo = new SqliteUserDataRepository(_loggerFactory.CreateLogger(), ApplicationPaths); + var userDataRepo = new SqliteUserDataRepository(LoggerFactory.CreateLogger(), ApplicationPaths); SetStaticProperties(); @@ -930,7 +937,7 @@ namespace Emby.Server.Implementations // localCert.PrivateKey = PrivateKey.CreateFromFile(pvk_file).RSA; if (!localCert.HasPrivateKey) { - _logger.LogError("No private key included in SSL cert {CertificateLocation}.", certificateLocation); + Logger.LogError("No private key included in SSL cert {CertificateLocation}.", certificateLocation); return null; } @@ -938,7 +945,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error loading cert from {CertificateLocation}", certificateLocation); + Logger.LogError(ex, "Error loading cert from {CertificateLocation}", certificateLocation); return null; } } @@ -950,7 +957,7 @@ namespace Emby.Server.Implementations private SqliteUserRepository GetUserRepository() { var repo = new SqliteUserRepository( - _loggerFactory.CreateLogger(), + LoggerFactory.CreateLogger(), ApplicationPaths); repo.Initialize(); @@ -960,7 +967,7 @@ namespace Emby.Server.Implementations private IAuthenticationRepository GetAuthenticationRepository() { - var repo = new AuthenticationRepository(_loggerFactory, ServerConfigurationManager); + var repo = new AuthenticationRepository(LoggerFactory, ServerConfigurationManager); repo.Initialize(); @@ -969,7 +976,7 @@ namespace Emby.Server.Implementations private IActivityRepository GetActivityLogRepository() { - var repo = new ActivityRepository(_loggerFactory, ServerConfigurationManager.ApplicationPaths, FileSystemManager); + var repo = new ActivityRepository(LoggerFactory, ServerConfigurationManager.ApplicationPaths, FileSystemManager); repo.Initialize(); @@ -984,7 +991,7 @@ namespace Emby.Server.Implementations ItemRepository.ImageProcessor = ImageProcessor; // For now there's no real way to inject these properly - BaseItem.Logger = _loggerFactory.CreateLogger("BaseItem"); + BaseItem.Logger = LoggerFactory.CreateLogger("BaseItem"); BaseItem.ConfigurationManager = ServerConfigurationManager; BaseItem.LibraryManager = LibraryManager; BaseItem.ProviderManager = ProviderManager; @@ -1117,7 +1124,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error getting plugin Id from {PluginName}.", plugin.GetType().FullName); + Logger.LogError(ex, "Error getting plugin Id from {PluginName}.", plugin.GetType().FullName); } } @@ -1128,7 +1135,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error loading plugin {PluginName}", plugin.GetType().FullName); + Logger.LogError(ex, "Error loading plugin {PluginName}", plugin.GetType().FullName); return null; } @@ -1140,7 +1147,7 @@ namespace Emby.Server.Implementations /// protected void DiscoverTypes() { - _logger.LogInformation("Loading assemblies"); + Logger.LogInformation("Loading assemblies"); _allConcreteTypes = GetTypes(GetComposablePartAssemblies()).ToArray(); } @@ -1156,7 +1163,7 @@ namespace Emby.Server.Implementations } catch (TypeLoadException ex) { - _logger.LogError(ex, "Error getting exported types from {Assembly}", ass.FullName); + Logger.LogError(ex, "Error getting exported types from {Assembly}", ass.FullName); continue; } @@ -1194,7 +1201,7 @@ namespace Emby.Server.Implementations }); } - protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(_loggerFactory.CreateLogger()); + protected IHttpListener CreateHttpListener() => new WebSocketSharpListener(LoggerFactory.CreateLogger()); private CertificateInfo GetCertificateInfo(bool generateCertificate) { @@ -1248,7 +1255,7 @@ namespace Emby.Server.Implementations if (requiresRestart) { - _logger.LogInformation("App needs to be restarted due to configuration change."); + Logger.LogInformation("App needs to be restarted due to configuration change."); NotifyPendingRestart(); } @@ -1259,7 +1266,7 @@ namespace Emby.Server.Implementations /// public void NotifyPendingRestart() { - _logger.LogInformation("App needs to be restarted."); + Logger.LogInformation("App needs to be restarted."); var changed = !HasPendingRestart; @@ -1267,7 +1274,7 @@ namespace Emby.Server.Implementations if (changed) { - EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, _logger); + EventHelper.QueueEventIfNotNull(HasPendingRestartChanged, this, EventArgs.Empty, Logger); } } @@ -1296,10 +1303,10 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error sending server restart notification"); + Logger.LogError(ex, "Error sending server restart notification"); } - _logger.LogInformation("Calling RestartInternal"); + Logger.LogInformation("Calling RestartInternal"); RestartInternal(); }); @@ -1324,11 +1331,11 @@ namespace Emby.Server.Implementations } catch (FileLoadException ex) { - _logger.LogError(ex, "Failed to load assembly {Path}", file); + Logger.LogError(ex, "Failed to load assembly {Path}", file); continue; } - _logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugAss.FullName, file); + Logger.LogInformation("Loaded assembly {Assembly} from {Path}", plugAss.FullName, file); yield return plugAss; } } @@ -1463,7 +1470,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error getting local Ip address information"); + Logger.LogError(ex, "Error getting local Ip address information"); } return null; @@ -1626,19 +1633,19 @@ namespace Emby.Server.Implementations var valid = string.Equals(Name, result, StringComparison.OrdinalIgnoreCase); _validAddressResults.AddOrUpdate(apiUrl, valid, (k, v) => valid); - _logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid); + Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, valid); return valid; } } } catch (OperationCanceledException) { - _logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled"); + Logger.LogDebug("Ping test result to {0}. Success: {1}", apiUrl, "Cancelled"); throw; } catch (Exception ex) { - _logger.LogDebug(ex, "Ping test result to {0}. Success: {1}", apiUrl, false); + Logger.LogDebug(ex, "Ping test result to {0}. Success: {1}", apiUrl, false); _validAddressResults.AddOrUpdate(apiUrl, false, (k, v) => false); return false; @@ -1668,7 +1675,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error sending server shutdown notification"); + Logger.LogError(ex, "Error sending server shutdown notification"); } ShutdownInternal(); @@ -1730,7 +1737,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error launching url: {url}", url); + Logger.LogError(ex, "Error launching url: {url}", url); throw; } } @@ -1770,14 +1777,14 @@ namespace Emby.Server.Implementations { var type = GetType(); - _logger.LogInformation("Disposing {Type}", type.Name); + Logger.LogInformation("Disposing {Type}", type.Name); var parts = _disposableParts.Distinct().Where(i => i.GetType() != type).ToList(); _disposableParts.Clear(); foreach (var part in parts) { - _logger.LogInformation("Disposing {Type}", part.GetType().Name); + Logger.LogInformation("Disposing {Type}", part.GetType().Name); try { @@ -1785,7 +1792,7 @@ namespace Emby.Server.Implementations } catch (Exception ex) { - _logger.LogError(ex, "Error disposing {Type}", part.GetType().Name); + Logger.LogError(ex, "Error disposing {Type}", part.GetType().Name); } } -- cgit v1.2.3 From 9aa259eb95bcb77fd1c1c7c4c115cbf6dcda7286 Mon Sep 17 00:00:00 2001 From: Mark Monteiro Date: Tue, 3 Mar 2020 23:56:47 +0100 Subject: Revert unnecessary ordering changes in ApplicationHost --- Emby.Server.Implementations/ApplicationHost.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'Emby.Server.Implementations/ApplicationHost.cs') diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 78b65e798..d51e74a4d 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -165,11 +165,6 @@ namespace Emby.Server.Implementations /// public bool IsShuttingDown { get; private set; } - /// - /// Gets the logger factory. - /// - protected ILoggerFactory LoggerFactory { get; } - /// /// Gets the logger. /// @@ -183,6 +178,11 @@ namespace Emby.Server.Implementations /// The plugins. public IReadOnlyList Plugins => _plugins; + /// + /// Gets the logger factory. + /// + protected ILoggerFactory LoggerFactory { get; } + /// /// Gets or sets the application paths. /// @@ -378,9 +378,10 @@ namespace Emby.Server.Implementations LoggerFactory = loggerFactory; FileSystemManager = fileSystem; - Logger = LoggerFactory.CreateLogger("App"); ConfigurationManager = new ServerConfigurationManager(ApplicationPaths, LoggerFactory, XmlSerializer, FileSystemManager); + Logger = LoggerFactory.CreateLogger("App"); + StartupOptions = options; ImageEncoder = imageEncoder; -- cgit v1.2.3