Use Microsoft.Extensions.Logging abstraction

This commit is contained in:
Bond_009
2018-12-13 14:18:25 +01:00
parent b0fd432126
commit 0f8b3c6347
310 changed files with 1421 additions and 2058 deletions

View File

@@ -18,6 +18,8 @@
<ItemGroup>
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.0.0" />
<PackageReference Include="SkiaSharp" Version="1.68.0" />
<PackageReference Include="SQLitePCLRaw.bundle_e_sqlite3" Version="1.1.11" />
<PackageReference Include="SQLitePCLRaw.core" Version="1.1.11" />

View File

@@ -6,7 +6,7 @@ using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.Net;
using MediaBrowser.Controller.Drawing;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using Emby.Drawing.Skia;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Globalization;
@@ -16,7 +16,6 @@ namespace MediaBrowser.Server.Startup.Common
public class ImageEncoderHelper
{
public static IImageEncoder GetImageEncoder(ILogger logger,
ILogManager logManager,
IFileSystem fileSystem,
StartupOptions startupOptions,
Func<IHttpClient> httpClient,
@@ -28,20 +27,20 @@ namespace MediaBrowser.Server.Startup.Common
{
try
{
return new SkiaEncoder(logManager.GetLogger("Skia"), appPaths, httpClient, fileSystem, localizationManager);
return new SkiaEncoder(logger, appPaths, httpClient, fileSystem, localizationManager);
}
catch (Exception ex)
{
logger.Info("Skia not available. Will try next image processor. {0}", ex.Message);
logger.LogInformation("Skia not available. Will try next image processor. {0}", ex.Message);
}
try
{
return new ImageMagickEncoder(logManager.GetLogger("ImageMagick"), appPaths, httpClient, fileSystem, environment);
return new ImageMagickEncoder(logger, appPaths, httpClient, fileSystem, environment);
}
catch
{
logger.Info("ImageMagick not available. Will try next image processor.");
logger.LogInformation("ImageMagick not available. Will try next image processor.");
}
}

View File

@@ -13,7 +13,7 @@ using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Sync;
using IsoMounter;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Services;
using MediaBrowser.Model.System;
@@ -21,7 +21,8 @@ namespace MediaBrowser.Server.Mono
{
public class MonoAppHost : ApplicationHost
{
public MonoAppHost(ServerApplicationPaths applicationPaths, ILogManager logManager, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager) : base(applicationPaths, logManager, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, networkManager)
public MonoAppHost(ServerApplicationPaths applicationPaths, ILoggerFactory loggerFactory, StartupOptions options, IFileSystem fileSystem, IPowerManagement powerManagement, string releaseAssetFilename, IEnvironmentInfo environmentInfo, MediaBrowser.Controller.Drawing.IImageEncoder imageEncoder, ISystemEvents systemEvents, MediaBrowser.Common.Net.INetworkManager networkManager)
: base(applicationPaths, loggerFactory, options, fileSystem, powerManagement, releaseAssetFilename, environmentInfo, imageEncoder, systemEvents, networkManager)
{
}
@@ -86,7 +87,8 @@ namespace MediaBrowser.Server.Mono
protected override IHttpListener CreateHttpListener()
{
return new EmbyServer.SocketSharp.WebSocketSharpListener(LogManager.GetLogger("HttpServer"),
return new EmbyServer.SocketSharp.WebSocketSharpListener(
Logger,
Certificate,
StreamHelper,
TextEncoding,

View File

@@ -1,5 +1,5 @@
using Emby.Server.Implementations.IO;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.System;
using Mono.Unix.Native;
@@ -15,7 +15,7 @@ namespace MediaBrowser.Server.Mono.Native
public override void SetExecutable(string path)
{
// Linux: File permission to 666, and user's execute bit
Logger.Info("Syscall.chmod {0} FilePermissions.DEFFILEMODE | FilePermissions.S_IRWXU | FilePermissions.S_IXGRP | FilePermissions.S_IXOTH", path);
Logger.LogInformation("Syscall.chmod {0} FilePermissions.DEFFILEMODE | FilePermissions.S_IRWXU | FilePermissions.S_IXGRP | FilePermissions.S_IXOTH", path);
Syscall.chmod(path, FilePermissions.DEFFILEMODE | FilePermissions.S_IRWXU | FilePermissions.S_IXGRP | FilePermissions.S_IXOTH);
}

View File

@@ -1,4 +1,3 @@
using MediaBrowser.Model.Logging;
using MediaBrowser.Server.Mono.Native;
using MediaBrowser.Server.Startup.Common;
using System;
@@ -15,16 +14,18 @@ using Emby.Drawing;
using Emby.Server.Implementations;
using Emby.Server.Implementations.EnvironmentInfo;
using Emby.Server.Implementations.IO;
using Emby.Server.Implementations.Logging;
using Emby.Server.Implementations.Networking;
using MediaBrowser.Controller;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
using Mono.Unix.Native;
using ILogger = MediaBrowser.Model.Logging.ILogger;
using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certificate;
using System.Threading;
using InteropServices = System.Runtime.InteropServices;
using Microsoft.Extensions.Logging;
using ILogger = Microsoft.Extensions.Logging.ILogger;
using Serilog;
using Serilog.AspNetCore;
namespace MediaBrowser.Server.Mono
{
@@ -33,7 +34,7 @@ namespace MediaBrowser.Server.Mono
private static ILogger _logger;
private static IFileSystem FileSystem;
private static IServerApplicationPaths _appPaths;
private static ILogManager _logManager;
private static ILoggerFactory _loggerFactory;
private static readonly TaskCompletionSource<bool> ApplicationTaskCompletionSource = new TaskCompletionSource<bool>();
private static bool _restartOnShutdown;
@@ -52,23 +53,24 @@ namespace MediaBrowser.Server.Mono
var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath);
_appPaths = appPaths;
using (var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"))
var logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
using (var loggerFactory = new SerilogLoggerFactory(logger))
{
_logManager = logManager;
_loggerFactory = loggerFactory;
var task = logManager.ReloadLogger(LogSeverity.Debug, CancellationToken.None);
Task.WaitAll(task);
logManager.AddConsoleOutput();
_logger = loggerFactory.CreateLogger("Main");
var logger = _logger = logManager.GetLogger("Main");
ApplicationHost.LogEnvironmentInfo(logger, appPaths, true);
ApplicationHost.LogEnvironmentInfo(_logger, appPaths, true);
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
RunApplication(appPaths, logManager, options);
RunApplication(appPaths, loggerFactory, options);
_logger.Info("Disposing app host");
_logger.LogInformation("Disposing app host");
if (_restartOnShutdown)
{
@@ -109,27 +111,27 @@ namespace MediaBrowser.Server.Mono
return new ServerApplicationPaths(programDataPath, appFolderPath, appFolderPath);
}
private static void RunApplication(ServerApplicationPaths appPaths, ILogManager logManager, StartupOptions options)
private static void RunApplication(ServerApplicationPaths appPaths, ILoggerFactory loggerFactory, StartupOptions options)
{
// Allow all https requests
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
var environmentInfo = GetEnvironmentInfo();
var fileSystem = new ManagedFileSystem(logManager.GetLogger("FileSystem"), environmentInfo, null, appPaths.TempDirectory, true);
var fileSystem = new ManagedFileSystem(loggerFactory.CreateLogger("FileSystem"), environmentInfo, null, appPaths.TempDirectory, true);
FileSystem = fileSystem;
using (var appHost = new MonoAppHost(appPaths,
logManager,
loggerFactory,
options,
fileSystem,
new PowerManagement(),
"embyserver-mono_{version}.zip",
environmentInfo,
new NullImageEncoder(),
new SystemEvents(logManager.GetLogger("SystemEvents")),
new NetworkManager(logManager.GetLogger("NetworkManager"), environmentInfo)))
new SystemEvents(loggerFactory.CreateLogger("SystemEvents")),
new NetworkManager(loggerFactory.CreateLogger("NetworkManager"), environmentInfo)))
{
if (options.ContainsOption("-v"))
{
@@ -141,7 +143,7 @@ namespace MediaBrowser.Server.Mono
appHost.Init();
appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, logManager, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager);
appHost.ImageProcessor.ImageEncoder = ImageEncoderHelper.GetImageEncoder(_logger, fileSystem, options, () => appHost.HttpClient, appPaths, environmentInfo, appHost.LocalizationManager);
Console.WriteLine("Running startup tasks");
@@ -221,7 +223,7 @@ namespace MediaBrowser.Server.Mono
}
catch (Exception ex)
{
_logger.ErrorException("Error getting unix name", ex);
_logger.LogError("Error getting unix name", ex);
}
_unixName = uname;
}
@@ -243,6 +245,8 @@ namespace MediaBrowser.Server.Mono
{
var exception = (Exception)e.ExceptionObject;
// TODO
/*
new UnhandledExceptionWriter(_appPaths, _logger, _logManager, FileSystem, new ConsoleLogger()).Log(exception);
if (!Debugger.IsAttached)
@@ -254,7 +258,7 @@ namespace MediaBrowser.Server.Mono
{
Environment.Exit(System.Runtime.InteropServices.Marshal.GetHRForException(exception));
}
}
}*/
}
public static void Shutdown()
@@ -271,7 +275,7 @@ namespace MediaBrowser.Server.Mono
private static void StartNewInstance(StartupOptions startupOptions)
{
_logger.Info("Starting new instance");
_logger.LogInformation("Starting new instance");
string module = startupOptions.GetOption("-restartpath");
string commandLineArgsString = startupOptions.GetOption("-restartargs") ?? string.Empty;
@@ -290,8 +294,8 @@ namespace MediaBrowser.Server.Mono
commandLineArgsString = string.Join(" ", args);
}
_logger.Info("Executable: {0}", module);
_logger.Info("Arguments: {0}", commandLineArgsString);
_logger.LogInformation("Executable: {0}", module);
_logger.LogInformation("Arguments: {0}", commandLineArgsString);
Process.Start(module, commandLineArgsString);
}

View File

@@ -1,5 +1,5 @@
using MediaBrowser.Common.Events;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;
@@ -55,7 +55,7 @@ namespace EmbyServer.SocketSharp
void socket_OnError(object sender, SocketHttpListener.ErrorEventArgs e)
{
_logger.Error("Error in SharpWebSocket: {0}", e.Message ?? string.Empty);
_logger.LogError("Error in SharpWebSocket: {0}", e.Message ?? string.Empty);
//EventHelper.FireEventIfNotNull(Closed, this, EventArgs.Empty, _logger);
}

View File

@@ -1,5 +1,5 @@
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using SocketHttpListener.Net;
using System;
using System.Collections.Generic;
@@ -74,7 +74,7 @@ namespace EmbyServer.SocketSharp
foreach (var prefix in urlPrefixes)
{
_logger.Info("Adding HttpListener prefix " + prefix);
_logger.LogInformation("Adding HttpListener prefix " + prefix);
_listener.Prefixes.Add(prefix);
}
@@ -93,7 +93,7 @@ namespace EmbyServer.SocketSharp
{
var url = request.Url.ToString();
logger.Info("{0} {1}. UserAgent: {2}", request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod, url, request.UserAgent ?? string.Empty);
logger.LogInformation("{0} {1}. UserAgent: {2}", request.IsWebSocketRequest ? "WS" : "HTTP " + request.HttpMethod, url, request.UserAgent ?? string.Empty);
}
private Task InitTask(HttpListenerContext context, CancellationToken cancellationToken)
@@ -114,7 +114,7 @@ namespace EmbyServer.SocketSharp
}
catch (Exception ex)
{
_logger.ErrorException("Error processing request", ex);
_logger.LogError("Error processing request", ex);
httpReq = httpReq ?? GetRequest(context);
return ErrorHandler(ex, httpReq, true, true);
@@ -148,7 +148,7 @@ namespace EmbyServer.SocketSharp
if (connectingArgs.AllowConnection)
{
_logger.Debug("Web socket connection allowed");
_logger.LogDebug("Web socket connection allowed");
var webSocketContext = await ctx.AcceptWebSocketAsync(null).ConfigureAwait(false);
@@ -169,14 +169,14 @@ namespace EmbyServer.SocketSharp
}
else
{
_logger.Warn("Web socket connection not allowed");
_logger.LogWarning("Web socket connection not allowed");
ctx.Response.StatusCode = 401;
ctx.Response.Close();
}
}
catch (Exception ex)
{
_logger.ErrorException("AcceptWebSocketAsync error", ex);
_logger.LogError("AcceptWebSocketAsync error", ex);
ctx.Response.StatusCode = 500;
ctx.Response.Close();
}
@@ -206,7 +206,7 @@ namespace EmbyServer.SocketSharp
}
catch (Exception ex)
{
_logger.ErrorException("Error closing web socket response", ex);
_logger.LogError("Error closing web socket response", ex);
}
}
@@ -259,4 +259,4 @@ namespace EmbyServer.SocketSharp
}
}
}
}

View File

@@ -4,7 +4,7 @@ using System.IO;
using System.Text;
using Emby.Server.Implementations.HttpServer;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Services;
using SocketHttpListener.Net;
using IHttpFile = MediaBrowser.Model.Services.IHttpFile;

View File

@@ -6,7 +6,7 @@ using System.Text;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using Microsoft.Extensions.Logging;
using MediaBrowser.Model.Services;
using HttpListenerResponse = SocketHttpListener.Net.HttpListenerResponse;
using IHttpResponse = MediaBrowser.Model.Services.IHttpResponse;
@@ -112,7 +112,7 @@ namespace EmbyServer.SocketSharp
}
catch (Exception ex)
{
_logger.ErrorException("Error in HttpListenerResponseWrapper: " + ex.Message, ex);
_logger.LogError("Error in HttpListenerResponseWrapper: " + ex.Message, ex);
}
}
}