changed logging to allow debugging

This commit is contained in:
2025-12-16 23:46:58 -05:00
parent 63fa071180
commit ea7ff0b051

View File

@@ -4,6 +4,8 @@ using Cronos;
using Renci.SshNet; using Renci.SshNet;
using Renci.SshNet.Sftp; using Renci.SshNet.Sftp;
using Serilog; using Serilog;
using Serilog.Core;
using Serilog.Events;
var resetEvent = new ManualResetEvent(false); var resetEvent = new ManualResetEvent(false);
using var tokenSource = new CancellationTokenSource(); using var tokenSource = new CancellationTokenSource();
@@ -30,14 +32,27 @@ return;
static void SetupLogging() 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() Log.Logger = new LoggerConfiguration()
.MinimumLevel.Information() .MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.Console() .WriteTo.Console()
.WriteTo.File("log.txt", .WriteTo.File("log.txt",
rollingInterval: RollingInterval.Day, rollingInterval: RollingInterval.Day,
rollOnFileSizeLimit: true, rollOnFileSizeLimit: true,
retainedFileCountLimit: 10) retainedFileCountLimit: 10)
.CreateLogger(); .CreateLogger();
Log.Debug($"Logging initialized at {minLevel}");
} }
static Config LoadConfig() static Config LoadConfig()
@@ -92,9 +107,12 @@ static async Task ScheduleJobs(Config config, CancellationToken token)
static async Task RunJob(Config config, CancellationToken token) static async Task RunJob(Config config, CancellationToken token)
{ {
using var client = GetClient(config.FTP); 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); var buffer = Math.Clamp(config.BufferSizeMB ?? 1, 0.5f, 4);
client.BufferSize = (uint)(1024 * 1024 * buffer); 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); await client.ConnectAsync(token);
foreach (var target in config.Targets) foreach (var target in config.Targets)
{ {