Added debugging around file move and file delete

This commit is contained in:
Robert McRackan 2022-03-30 09:52:39 -04:00
parent cbc61f5a2d
commit 962e379642
2 changed files with 23 additions and 11 deletions

View File

@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>net6.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<Version>6.7.3.1</Version> <Version>6.7.4.1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -189,15 +189,19 @@ namespace FileManager
{ {
try try
{ {
if (File.Exists(source)) if (!File.Exists(source))
{ {
File.Delete(source); Serilog.Log.Logger.Debug("No file to delete: {@DebugText}", new { source });
Serilog.Log.Logger.Information("File successfully deleted", 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) 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; throw;
} }
}); });
@ -208,17 +212,25 @@ namespace FileManager
{ {
try try
{ {
if (File.Exists(source)) if (!File.Exists(source))
{ {
SaferDelete(destination); Serilog.Log.Logger.Debug("No file to move: {@DebugText}", new { source });
Directory.CreateDirectory(Path.GetDirectoryName(destination)); return;
File.Move(source, destination);
Serilog.Log.Logger.Information("File successfully moved", new { source, destination });
} }
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) 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; throw;
} }
}); });