From 523441dd2f874c3f5b42a0aa6878479137fa9d9e Mon Sep 17 00:00:00 2001 From: Boxfriend Date: Wed, 17 Dec 2025 00:15:43 -0500 Subject: [PATCH] extra logging --- Program.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Program.cs b/Program.cs index 642d98c..d62ef0b 100644 --- a/Program.cs +++ b/Program.cs @@ -15,19 +15,20 @@ Console.CancelKeyPress += (_, eventArgs) => Log.Debug("Canceling with CancelKeyPress"); Dispose(); eventArgs.Cancel = true; - Log.CloseAndFlush(); }; AppDomain.CurrentDomain.ProcessExit += (_, _) => Dispose(); SetupLogging(); +//TODO: check environment variables to see if config file is enabled, otherwise use env vars var config = LoadConfig(); Log.Information("Configuration file loaded. Beginning initial grab."); await RunJob(config, tokenSource.Token); Log.Information("Initial grab complete. Initializing schedule."); Task.Run(() => ScheduleJobs(config, tokenSource.Token)); +Log.Verbose("Jobs scheduled. Main Thread waiting."); resetEvent.WaitOne(); return; @@ -72,13 +73,14 @@ static Config LoadConfig() WriteIndented = true }; + //TODO: stop creating dummy config file if (!File.Exists("/config.json")) { Log.Fatal("No config file found, creating dummy config."); CreateConfig(serializationOptions); Environment.Exit(1); } - + Log.Verbose("Loading config from file."); var configFile = File.ReadAllText("/config.json"); return JsonSerializer.Deserialize(configFile, serializationOptions); } @@ -93,6 +95,7 @@ static void CreateConfig(JsonSerializerOptions options) static async Task ScheduleJobs(Config config, CancellationToken token) { + Log.Debug($"Scheduling job with cron expression '{config.Schedule}'"); var schedule = CronExpression.Parse(config.Schedule); while (!token.IsCancellationRequested) @@ -104,11 +107,12 @@ static async Task ScheduleJobs(Config config, CancellationToken token) Log.Information($"Next scheduled scan at {nextJob.Value}"); var delay = nextJob.Value - now; + Log.Debug($"{delay} until next scan at {nextJob.Value}"); if (delay > TimeSpan.Zero) { await Task.Delay(delay, token); } - + Log.Debug($"Delay {delay} wait is complete, beginning scan now."); await RunJob(config, token); } } @@ -140,11 +144,13 @@ static async Task RecurseDirectory(SftpClient client, string source, string dest if (item.IsDirectory) { + Log.Verbose($"{item.Name} is a directory"); var newPath = Path.Combine(destination, item.Name); await RecurseDirectory(client, item.FullName, newPath, true, token); return; } - + + Log.Verbose($"{item.Name} is a file"); await DownloadFile(client, item, destination, token); Log.Information($"Deleting '{item.Name}'"); await client.DeleteAsync(item.FullName, token); @@ -160,9 +166,11 @@ static async Task RecurseDirectory(SftpClient client, string source, string dest static async Task DownloadFile(SftpClient client, ISftpFile item, string destination, CancellationToken token) { Directory.CreateDirectory(destination); + Log.Verbose($"Ensuring '{destination}' path exists."); await using var stream = File.Open(Path.Combine(destination, item.Name), FileMode.Create, FileAccess.Write); Log.Information($"Downloading '{item.FullName}' to '{stream.Name}'"); await client.DownloadFileAsync(item.FullName, stream, token); + Log.Verbose("Download completed."); } static SftpClient GetClient(SFtpTarget target)