mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-20 20:50:36 +02:00
Added logging.json file
This commit is contained in:
parent
88f5471fe3
commit
a51798dd8d
|
@ -17,9 +17,13 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<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="Serilog.Settings.Configuration" Version="3.0.1" />
|
||||
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
|
||||
<PackageReference Include="Serilog.Sinks.File" Version="4.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" />
|
||||
|
@ -50,6 +54,10 @@
|
|||
<ProjectReference Include="..\SocketHttpListener\SocketHttpListener.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Resources/Configuration/*" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="..\SharedVersion.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -23,6 +23,7 @@ using X509Certificate = System.Security.Cryptography.X509Certificates.X509Certif
|
|||
using System.Threading;
|
||||
using InteropServices = System.Runtime.InteropServices;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
using Serilog;
|
||||
using Serilog.AspNetCore;
|
||||
|
@ -53,12 +54,9 @@ namespace MediaBrowser.Server.Mono
|
|||
var appPaths = CreateApplicationPaths(applicationPath, customProgramDataPath);
|
||||
_appPaths = appPaths;
|
||||
|
||||
using (var loggerFactory = new SerilogLoggerFactory(
|
||||
new LoggerConfiguration()
|
||||
.Enrich.FromLogContext()
|
||||
.WriteTo.Console()
|
||||
.CreateLogger()
|
||||
, true))
|
||||
createLogger();
|
||||
|
||||
using (var loggerFactory = new SerilogLoggerFactory())
|
||||
{
|
||||
_loggerFactory = loggerFactory;
|
||||
|
||||
|
@ -156,6 +154,47 @@ namespace MediaBrowser.Server.Mono
|
|||
}
|
||||
}
|
||||
|
||||
private static async Task createLogger()
|
||||
{
|
||||
try
|
||||
{
|
||||
string path = Path.Combine(_appPaths.ProgramDataPath, "logging.json");
|
||||
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
var assembly = typeof(MainClass).Assembly;
|
||||
// For some reason the csproj name is used instead of the assembly name
|
||||
var resourcePath = "EmbyServer.Resources.Configuration.logging.json";
|
||||
using (Stream rscstr = assembly.GetManifestResourceStream(resourcePath))
|
||||
using (Stream fstr = File.Open(path, FileMode.CreateNew))
|
||||
{
|
||||
await rscstr.CopyToAsync(fstr);
|
||||
}
|
||||
}
|
||||
var configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile(path)
|
||||
.Build();
|
||||
|
||||
Serilog.Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.Enrich.FromLogContext()
|
||||
.CreateLogger();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Serilog.Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console(outputTemplate: "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message:lj}{NewLine}{Exception}")
|
||||
.WriteTo.File(
|
||||
Path.Combine(AppContext.BaseDirectory, "logs", "log_.log"),
|
||||
rollingInterval: RollingInterval.Day,
|
||||
outputTemplate: "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}")
|
||||
.Enrich.FromLogContext()
|
||||
.CreateLogger();
|
||||
|
||||
Serilog.Log.Logger.Fatal(ex, "Failed to read logger config");
|
||||
}
|
||||
}
|
||||
|
||||
private static MonoEnvironmentInfo GetEnvironmentInfo()
|
||||
{
|
||||
var info = new MonoEnvironmentInfo();
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"Serilog": {
|
||||
"MinimumLevel": "Information",
|
||||
"WriteTo": [
|
||||
{ "Name": "Console",
|
||||
"Args": {
|
||||
"outputTemplate": "[{Timestamp:HH:mm:ss}] [{Level:u3}] {Message}{NewLine}{Exception}"
|
||||
}
|
||||
},
|
||||
{ "Name": "File",
|
||||
"Args": {
|
||||
"path": "logs//log_.log",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz}] [{Level:u3}] {Message}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue