Merge pull request #1311 from Mbucari/master
Fix serilog dynamic assembly loading issue (#1310)
This commit is contained in:
commit
829b35c5a8
@ -118,6 +118,7 @@ namespace FileLiberator
|
||||
}
|
||||
catch when (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
Serilog.Log.Logger.Information("Download/Decrypt was cancelled. {@Book}", libraryBook.LogFriendly());
|
||||
return new StatusHandler { "Cancelled" };
|
||||
}
|
||||
finally
|
||||
|
||||
@ -5,6 +5,8 @@ using FileManager;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
using Serilog.Exceptions;
|
||||
using Serilog.Settings.Configuration;
|
||||
|
||||
#nullable enable
|
||||
namespace LibationFileManager
|
||||
@ -15,11 +17,25 @@ namespace LibationFileManager
|
||||
|
||||
public void ConfigureLogging()
|
||||
{
|
||||
//pass explicit assemblies to the ConfigurationReaderOptions
|
||||
//This is a workaround for the issue where serilog will try to load all
|
||||
//Assemblies starting with "serilog" from the app folder, but it will fail
|
||||
//if those assemblies are unreferenced.
|
||||
//This was a problem when migrating from the ZipFile sink to the File sink.
|
||||
//Upgrading users would still have the ZipFile sink dll in the program
|
||||
//folder and serilog would try to load it, unsuccessfully.
|
||||
//https://github.com/serilog/serilog-settings-configuration/issues/406
|
||||
var readerOptions = new ConfigurationReaderOptions(
|
||||
typeof(ILogger).Assembly, // Serilog
|
||||
typeof(LoggerEnrichmentConfigurationExtensions).Assembly, // Serilog.Exceptions
|
||||
typeof(ConsoleLoggerConfigurationExtensions).Assembly, // Serilog.Sinks.Console
|
||||
typeof(FileLoggerConfigurationExtensions).Assembly); // Serilog.Sinks.File
|
||||
|
||||
configuration = new ConfigurationBuilder()
|
||||
.AddJsonFile(SettingsFilePath, optional: false, reloadOnChange: true)
|
||||
.Build();
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(configuration)
|
||||
.ReadFrom.Configuration(configuration, readerOptions)
|
||||
.Destructure.ByTransforming<LongPath>(lp => lp.Path)
|
||||
.Destructure.With<LogFileFilter>()
|
||||
.CreateLogger();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user