Fix and improve logging

This commit is contained in:
Bond_009 2019-01-01 18:41:02 +01:00 committed by Vasily
parent 75efe9cf0a
commit a44936f97f
5 changed files with 56 additions and 45 deletions

View File

@ -799,27 +799,6 @@ namespace Emby.Server.Implementations
JsonSerializer = CreateJsonSerializer();
OnLoggerLoaded(true);
//LoggerFactory.LoggerLoaded += (s, e) => OnLoggerLoaded(false);
DiscoverTypes();
SetHttpLimit();
RegisterResources();
FindParts();
}
protected virtual void OnLoggerLoaded(bool isFirstLoad)
{
Logger.LogInformation("Application version: {0}", ApplicationVersion);
if (!isFirstLoad)
{
LogEnvironmentInfo(Logger, ApplicationPaths, false);
}
if (Plugins != null)
{
var pluginBuilder = new StringBuilder();
@ -831,6 +810,14 @@ namespace Emby.Server.Implementations
Logger.LogInformation("Plugins: {plugins}", pluginBuilder.ToString());
}
DiscoverTypes();
SetHttpLimit();
RegisterResources();
FindParts();
}
protected virtual IHttpClient CreateHttpClient()
@ -1073,36 +1060,27 @@ namespace Emby.Server.Implementations
{
get
{
return "netframework";
return "netcore";
}
}
public static void LogEnvironmentInfo(ILogger Logger, IApplicationPaths appPaths, bool isStartup)
{
Logger.LogInformation("Jellyfin:\n{ex}", GetBaseExceptionMessage(appPaths).ToString());
}
protected static StringBuilder GetBaseExceptionMessage(IApplicationPaths appPaths)
public static void LogEnvironmentInfo(ILogger logger, IApplicationPaths appPaths, EnvironmentInfo.EnvironmentInfo environmentInfo)
{
var builder = new StringBuilder();
// Distinct these to prevent users from reporting problems that aren't actually problems
var commandLineArgs = Environment
.GetCommandLineArgs()
.Distinct()
.ToArray();
.Distinct();
builder.AppendLine(string.Format("Command line: {0}", string.Join(" ", commandLineArgs)));
builder.AppendLine(string.Format("Operating system: {0}", Environment.OSVersion));
builder.AppendLine(string.Format("64-Bit OS: {0}", Environment.Is64BitOperatingSystem));
builder.AppendLine(string.Format("64-Bit Process: {0}", Environment.Is64BitProcess));
builder.AppendLine(string.Format("User Interactive: {0}", Environment.UserInteractive));
builder.AppendLine(string.Format("Processor count: {0}", Environment.ProcessorCount));
builder.AppendLine(string.Format("Program data path: {0}", appPaths.ProgramDataPath));
builder.AppendLine(string.Format("Application directory: {0}", appPaths.ProgramSystemPath));
return builder;
logger.LogInformation("Arguments: {Args}", commandLineArgs);
logger.LogInformation("Operating system: {OS} {OSVersion}", environmentInfo.OperatingSystemName, environmentInfo.OperatingSystemVersion);
logger.LogInformation("Architecture: {Architecture}", environmentInfo.SystemArchitecture);
logger.LogInformation("64-Bit Process: {0}", Environment.Is64BitProcess);
logger.LogInformation("User Interactive: {0}", Environment.UserInteractive);
logger.LogInformation("Processor count: {0}", Environment.ProcessorCount);
logger.LogInformation("Program data path: {0}", appPaths.ProgramDataPath);
logger.LogInformation("Application directory: {0}", appPaths.ProgramSystemPath);
}
private void SetHttpLimit()

View File

@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
namespace Emby.Server.Implementations.EnvironmentInfo
{
// TODO: Rework @bond
public class EnvironmentInfo : IEnvironmentInfo
{
private MediaBrowser.Model.System.OperatingSystem? _customOperatingSystem;
@ -40,7 +41,14 @@ namespace Emby.Server.Implementations.EnvironmentInfo
{
get
{
return Environment.OSVersion.Platform.ToString();
switch (OperatingSystem) {
case MediaBrowser.Model.System.OperatingSystem.Android: return "Android";
case MediaBrowser.Model.System.OperatingSystem.BSD: return "BSD";
case MediaBrowser.Model.System.OperatingSystem.Linux: return "Linux";
case MediaBrowser.Model.System.OperatingSystem.OSX: return "macOS";
case MediaBrowser.Model.System.OperatingSystem.Windows: return "Windows";
default: throw new Exception($"Unknown OS {OperatingSystem}");
}
}
}

View File

@ -15,6 +15,10 @@
<Compile Include="..\SharedVersion.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources/Configuration/*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />

View File

@ -59,14 +59,16 @@ namespace Jellyfin.Server
AppDomain.CurrentDomain.UnhandledException += (sender, e)
=> _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");;
ApplicationHost.LogEnvironmentInfo(_logger, appPaths, true);
_logger.LogInformation("Jellyfin version: {Version}", entryAssembly.GetName().Version);
EnvironmentInfo environmentInfo = getEnvironmentInfo();
ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo);
SQLitePCL.Batteries_V2.Init();
// Allow all https requests
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(delegate { return true; });
EnvironmentInfo environmentInfo = getEnvironmentInfo();
var fileSystem = new ManagedFileSystem(_loggerFactory.CreateLogger("FileSystem"), environmentInfo, null, appPaths.TempDirectory, true);
using (var appHost = new CoreAppHost(
@ -144,7 +146,7 @@ namespace Jellyfin.Server
{
// For some reason the csproj name is used instead of the assembly name
using (Stream rscstr = typeof(Program).Assembly
.GetManifestResourceStream("EmbyServer.Resources.Configuration.logging.json"))
.GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json"))
using (Stream fstr = File.Open(path, FileMode.CreateNew))
{
await rscstr.CopyToAsync(fstr);

View File

@ -0,0 +1,19 @@
{
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{ "Name": "Console",
"Args": {
"outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}"
}
},
{ "Name": "File",
"Args": {
"path": "%JELLYFIN_LOG_DIR%//log_.log",
"rollingInterval": "Day",
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}"
}
}
]
}
}