diff --git a/Program.cs b/Program.cs index b82167f..bd24964 100644 --- a/Program.cs +++ b/Program.cs @@ -4,6 +4,8 @@ using Cronos; using Renci.SshNet; using Renci.SshNet.Sftp; using Serilog; +using Serilog.Core; +using Serilog.Events; var resetEvent = new ManualResetEvent(false); using var tokenSource = new CancellationTokenSource(); @@ -30,14 +32,27 @@ return; static void SetupLogging() { + var minLevel = (Environment.GetEnvironmentVariable("LOG_LEVEL") ?? "info").ToUpperInvariant() switch + { + "VERBOSE" => LogEventLevel.Verbose, + "DEBUG" => LogEventLevel.Debug, + "WARNING" => LogEventLevel.Warning, + "ERROR" => LogEventLevel.Error, + "FATAL" => LogEventLevel.Fatal, + _ => LogEventLevel.Information + }; + var levelSwitch = new LoggingLevelSwitch(minLevel); + Log.Logger = new LoggerConfiguration() - .MinimumLevel.Information() + .MinimumLevel.ControlledBy(levelSwitch) .WriteTo.Console() .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day, rollOnFileSizeLimit: true, retainedFileCountLimit: 10) .CreateLogger(); + + Log.Debug($"Logging initialized at {minLevel}"); } static Config LoadConfig() @@ -92,9 +107,12 @@ static async Task ScheduleJobs(Config config, CancellationToken token) static async Task RunJob(Config config, CancellationToken token) { using var client = GetClient(config.FTP); + Log.Information($"Connecting to {config.FTP.Host}:{config.FTP.Port} as {config.FTP.UserName}"); + var buffer = Math.Clamp(config.BufferSizeMB ?? 1, 0.5f, 4); client.BufferSize = (uint)(1024 * 1024 * buffer); - Log.Information($"Connecting to {config.FTP.Host}:{config.FTP.Port} as {config.FTP.UserName}"); + Log.Debug($"Connection buffer size: {client.BufferSize}"); + await client.ConnectAsync(token); foreach (var target in config.Targets) {