diff options
| -rw-r--r-- | Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs | 24 | ||||
| -rw-r--r-- | Emby.Server.Implementations/ServerApplicationPaths.cs | 4 | ||||
| -rw-r--r-- | Jellyfin.Server/Program.cs | 51 | ||||
| -rw-r--r-- | MediaBrowser.Api/System/SystemService.cs | 10 |
4 files changed, 54 insertions, 35 deletions
diff --git a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs index 52e421374..76d0076a6 100644 --- a/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs +++ b/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System.IO; using MediaBrowser.Common.Configuration; namespace Emby.Server.Implementations.AppBase @@ -13,10 +12,11 @@ namespace Emby.Server.Implementations.AppBase /// <summary> /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class. /// </summary> - protected BaseApplicationPaths(string programDataPath, string appFolderPath) + protected BaseApplicationPaths(string programDataPath, string appFolderPath, string logDirectoryPath) { ProgramDataPath = programDataPath; ProgramSystemPath = appFolderPath; + LogDirectoryPath = logDirectoryPath; } public string ProgramDataPath { get; private set; } @@ -107,6 +107,11 @@ namespace Emby.Server.Implementations.AppBase } /// <summary> + /// The _log directory + /// </summary> + private string _logDirectoryPath; + + /// <summary> /// Gets the path to the log directory /// </summary> /// <value>The log directory path.</value> @@ -114,7 +119,18 @@ namespace Emby.Server.Implementations.AppBase { get { - return Path.Combine(ProgramDataPath, "logs"); + if (string.IsNullOrEmpty(_logDirectoryPath)) + { + _logDirectoryPath = Path.Combine(ProgramDataPath, "logs"); + + Directory.CreateDirectory(_logDirectoryPath); + } + + return _logDirectoryPath; + } + set + { + _logDirectoryPath = value; } } diff --git a/Emby.Server.Implementations/ServerApplicationPaths.cs b/Emby.Server.Implementations/ServerApplicationPaths.cs index 1686a548b..f5986f943 100644 --- a/Emby.Server.Implementations/ServerApplicationPaths.cs +++ b/Emby.Server.Implementations/ServerApplicationPaths.cs @@ -13,8 +13,8 @@ namespace Emby.Server.Implementations /// <summary> /// Initializes a new instance of the <see cref="BaseApplicationPaths" /> class. /// </summary> - public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath) - : base(programDataPath, appFolderPath) + public ServerApplicationPaths(string programDataPath, string appFolderPath, string applicationResourcesPath, string logDirectoryPath = null) + : base(programDataPath, appFolderPath, logDirectoryPath) { ApplicationResourcesPath = applicationResourcesPath; } diff --git a/Jellyfin.Server/Program.cs b/Jellyfin.Server/Program.cs index dd5e427df..aef22e020 100644 --- a/Jellyfin.Server/Program.cs +++ b/Jellyfin.Server/Program.cs @@ -39,27 +39,23 @@ namespace Jellyfin.Server public static async Task<int> Main(string[] args)
{
StartupOptions options = new StartupOptions(args);
-
- Assembly entryAssembly = Assembly.GetEntryAssembly();
+ Version version = Assembly.GetEntryAssembly().GetName().Version;
if (options.ContainsOption("-v") || options.ContainsOption("--version"))
{
- Console.WriteLine(entryAssembly.GetName().Version.ToString());
+ Console.WriteLine(version.ToString());
return 0;
}
- string dataPath = options.GetOption("-programdata");
- string binPath = entryAssembly.Location;
- ServerApplicationPaths appPaths = CreateApplicationPaths(binPath, dataPath);
-
+ ServerApplicationPaths appPaths = createApplicationPaths(options);
await createLogger(appPaths);
_loggerFactory = new SerilogLoggerFactory();
_logger = _loggerFactory.CreateLogger("Main");
AppDomain.CurrentDomain.UnhandledException += (sender, e)
- => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");;
+ => _logger.LogCritical((Exception)e.ExceptionObject, "Unhandled Exception");
- _logger.LogInformation("Jellyfin version: {Version}", entryAssembly.GetName().Version);
+ _logger.LogInformation("Jellyfin version: {Version}", version);
EnvironmentInfo environmentInfo = getEnvironmentInfo();
ApplicationHost.LogEnvironmentInfo(_logger, appPaths, environmentInfo);
@@ -106,9 +102,14 @@ namespace Jellyfin.Server return 0;
}
- private static ServerApplicationPaths CreateApplicationPaths(string applicationPath, string programDataPath)
+ private static ServerApplicationPaths createApplicationPaths(StartupOptions options)
{
- if (string.IsNullOrEmpty(programDataPath))
+ string programDataPath;
+ if (options.ContainsOption("-programdata"))
+ {
+ programDataPath = options.GetOption("-programdata");
+ }
+ else
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
@@ -126,28 +127,30 @@ namespace Jellyfin.Server programDataPath = Path.Combine(programDataPath, "jellyfin");
}
- string appFolderPath = Path.GetDirectoryName(applicationPath);
+ string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
+ if (string.IsNullOrEmpty(logDir)){
+ logDir = Path.Combine(programDataPath, "logs");
+ // $JELLYFIN_LOG_DIR needs to be set for the logger configuration manager
+ Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", logDir);
+ }
+
+ string appPath = Assembly.GetEntryAssembly().Location;
- return new ServerApplicationPaths(programDataPath, appFolderPath, appFolderPath);
+ return new ServerApplicationPaths(programDataPath, appPath, appPath, logDir);
}
private static async Task createLogger(IApplicationPaths appPaths)
{
- string logDir = Environment.GetEnvironmentVariable("JELLYFIN_LOG_DIR");
- if (string.IsNullOrEmpty(logDir)){
- logDir = Path.Combine(appPaths.ProgramDataPath, "logs");
- Environment.SetEnvironmentVariable("JELLYFIN_LOG_DIR", logDir);
- }
try
{
- string path = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json");
+ string configPath = Path.Combine(appPaths.ConfigurationDirectoryPath, "logging.json");
- if (!File.Exists(path))
+ if (!File.Exists(configPath))
{
// For some reason the csproj name is used instead of the assembly name
using (Stream rscstr = typeof(Program).Assembly
.GetManifestResourceStream("Jellyfin.Server.Resources.Configuration.logging.json"))
- using (Stream fstr = File.Open(path, FileMode.CreateNew))
+ using (Stream fstr = File.Open(configPath, FileMode.CreateNew))
{
await rscstr.CopyToAsync(fstr);
}
@@ -169,7 +172,7 @@ namespace Jellyfin.Server Serilog.Log.Logger = new LoggerConfiguration()
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}")
.WriteTo.File(
- Path.Combine(logDir, "log_.log"),
+ Path.Combine(appPaths.LogDirectoryPath, "log_.log"),
rollingInterval: RollingInterval.Day,
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}")
.Enrich.FromLogContext()
@@ -227,6 +230,7 @@ namespace Jellyfin.Server case PlatformID.Win32NT:
return MediaBrowser.Model.System.OperatingSystem.Windows;
case PlatformID.Unix:
+ default:
{
string osDescription = RuntimeInformation.OSDescription;
if (osDescription.Contains("linux", StringComparison.OrdinalIgnoreCase))
@@ -241,9 +245,8 @@ namespace Jellyfin.Server {
return MediaBrowser.Model.System.OperatingSystem.BSD;
}
- throw new Exception($"Can't resolve OS with description: {Environment.OSVersion.Platform}");
+ throw new Exception($"Can't resolve OS with description: '{osDescription}'");
}
- default: throw new Exception($"Can't resolve OS with description: {Environment.OSVersion.Platform}");
}
}
diff --git a/MediaBrowser.Api/System/SystemService.cs b/MediaBrowser.Api/System/SystemService.cs index d2880f735..52e14dbcc 100644 --- a/MediaBrowser.Api/System/SystemService.cs +++ b/MediaBrowser.Api/System/SystemService.cs @@ -9,12 +9,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; - -using MediaBrowser.Controller.IO; using MediaBrowser.Model.IO; using MediaBrowser.Model.Net; using MediaBrowser.Model.Services; using System.Threading; +using Microsoft.Extensions.Logging; namespace MediaBrowser.Api.System { @@ -137,11 +136,12 @@ namespace MediaBrowser.Api.System try { - files = _fileSystem.GetFiles(_appPaths.LogDirectoryPath, new[] { ".txt" }, true, false); + files = _fileSystem.GetFiles(_appPaths.LogDirectoryPath, new[] { ".txt", ".log" }, true, false); } - catch (IOException) + catch (IOException ex) { - files = new FileSystemMetadata[] { }; + Logger.LogError(ex, "Error getting logs"); + files = Enumerable.Empty<FileSystemMetadata>(); } var result = files.Select(i => new LogFile |
