refactor: Add support for custom log sinks

pull/314/head
Robert Dailey 6 months ago
parent 08b88fa0b7
commit 94430f394d

@ -7,7 +7,7 @@ using Serilog.Templates.Themes;
namespace Recyclarr.Cli.Logging;
public class LoggerFactory(IAppPaths paths, LoggingLevelSwitch levelSwitch, IEnvironment env)
public class LoggerFactory(IAppPaths paths, LoggingLevelSwitch levelSwitch, IEnvironment env, IEnumerable<ILogEventSink> sinks)
{
private static string GetBaseTemplateString()
{
@ -41,7 +41,7 @@ public class LoggerFactory(IAppPaths paths, LoggingLevelSwitch levelSwitch, IEnv
var logFilePrefix = $"recyclarr_{DateTime.Now:yyyy-MM-dd_HH-mm-ss}";
var logDir = paths.LogDirectory;
return new LoggerConfiguration()
var config = new LoggerConfiguration()
.MinimumLevel.Is(LogEventLevel.Verbose)
.Enrich.FromLogContext()
.Enrich.With<FlurlExceptionSanitizingEnricher>()
@ -51,8 +51,14 @@ public class LoggerFactory(IAppPaths paths, LoggingLevelSwitch levelSwitch, IEnv
.WriteTo.File(GetFileTemplate(), LogFilePath("debug")))
.WriteTo.Logger(c => c
.Filter.ByIncludingOnly(e => e.Level == LogEventLevel.Verbose)
.WriteTo.File(GetFileTemplate(), LogFilePath("verbose")))
.CreateLogger();
.WriteTo.File(GetFileTemplate(), LogFilePath("verbose")));
foreach (var sink in sinks)
{
config.WriteTo.Sink(sink, levelSwitch: levelSwitch);
}
return config.CreateLogger();
string LogFilePath(string type)
{

Loading…
Cancel
Save