From 962e3796429d22a618f1fc5b1faa4aa0b08c2bf7 Mon Sep 17 00:00:00 2001 From: Robert McRackan Date: Wed, 30 Mar 2022 09:52:39 -0400 Subject: [PATCH] Added debugging around file move and file delete --- AppScaffolding/AppScaffolding.csproj | 2 +- FileManager/FileUtility.cs | 32 +++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/AppScaffolding/AppScaffolding.csproj b/AppScaffolding/AppScaffolding.csproj index f573ee3c..00c11946 100644 --- a/AppScaffolding/AppScaffolding.csproj +++ b/AppScaffolding/AppScaffolding.csproj @@ -3,7 +3,7 @@ net6.0 - 6.7.3.1 + 6.7.4.1 diff --git a/FileManager/FileUtility.cs b/FileManager/FileUtility.cs index 844c7513..22278917 100644 --- a/FileManager/FileUtility.cs +++ b/FileManager/FileUtility.cs @@ -189,15 +189,19 @@ namespace FileManager { try { - if (File.Exists(source)) + if (!File.Exists(source)) { - File.Delete(source); - Serilog.Log.Logger.Information("File successfully deleted", new { source }); + Serilog.Log.Logger.Debug("No file to delete: {@DebugText}", new { source }); + return; } + + Serilog.Log.Logger.Debug("Attempt to delete file: {@DebugText}", new { source }); + File.Delete(source); + Serilog.Log.Logger.Information("File successfully deleted: {@DebugText}", new { source }); } catch (Exception e) { - Serilog.Log.Logger.Error(e, "Failed to delete file", new { source }); + Serilog.Log.Logger.Error(e, "Failed to delete file: {@DebugText}", new { source }); throw; } }); @@ -208,17 +212,25 @@ namespace FileManager { try { - if (File.Exists(source)) + if (!File.Exists(source)) { - SaferDelete(destination); - Directory.CreateDirectory(Path.GetDirectoryName(destination)); - File.Move(source, destination); - Serilog.Log.Logger.Information("File successfully moved", new { source, destination }); + Serilog.Log.Logger.Debug("No file to move: {@DebugText}", new { source }); + return; } + + SaferDelete(destination); + + var dir = Path.GetDirectoryName(destination); + Serilog.Log.Logger.Debug("Attempt to create directory: {@DebugText}", new { dir }); + Directory.CreateDirectory(dir); + + Serilog.Log.Logger.Debug("Attempt to move file: {@DebugText}", new { source, destination }); + File.Move(source, destination); + Serilog.Log.Logger.Information("File successfully moved: {@DebugText}", new { source, destination }); } catch (Exception e) { - Serilog.Log.Logger.Error(e, "Failed to move file", new { source, destination }); + Serilog.Log.Logger.Error(e, "Failed to move file: {@DebugText}", new { source, destination }); throw; } });