From 74afbbf5815a255d8864296e105b73d82bc9eac9 Mon Sep 17 00:00:00 2001 From: MBucari Date: Sun, 23 Nov 2025 23:40:23 -0700 Subject: [PATCH] Add more liberation logging --- Source/FileLiberator/DownloadDecryptBook.cs | 19 ++++++++++++++++++- .../ProcessQueue/ProcessBookViewModel.cs | 2 ++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/Source/FileLiberator/DownloadDecryptBook.cs b/Source/FileLiberator/DownloadDecryptBook.cs index 302267c4..a00369b3 100644 --- a/Source/FileLiberator/DownloadDecryptBook.cs +++ b/Source/FileLiberator/DownloadDecryptBook.cs @@ -70,13 +70,16 @@ namespace FileLiberator //Set the last downloaded information on the book so that it can be used in the naming templates, //but don't persist it until everything completes successfully (in the finally block) + Serilog.Log.Verbose("Setting last downloaded info for {@Book}", libraryBook.LogFriendly()); var audioFormat = GetFileFormatInfo(downloadOptions, audioFile); var audioVersion = downloadOptions.ContentMetadata.ContentReference.Version; libraryBook.Book.UserDefinedItem.SetLastDownloaded(Configuration.LibationVersion, audioFormat, audioVersion); + //Verbose logging inside getDestinationDirectory var finalStorageDir = getDestinationDirectory(libraryBook); //post-download tasks done in parallel. + Serilog.Log.Verbose("Starting post-liberation finalization tasks"); var moveFilesTask = Task.Run(() => MoveFilesToBooksDir(libraryBook, finalStorageDir, result.ResultFiles, cancellationToken)); Task[] finalTasks = [ @@ -89,19 +92,26 @@ namespace FileLiberator try { + Serilog.Log.Verbose("Awaiting post-liberation finalization tasks"); await Task.WhenAll(finalTasks); } - catch when (!moveFilesTask.IsFaulted) + catch (Exception ex) { + Serilog.Log.Verbose(ex, "An error occurred in the post-liberation finalization tasks"); //Swallow DownloadCoverArt, DownloadRecordsAsync, DownloadMetadataAsync, and SetCoverAsFolderIcon exceptions. //Only fail if the downloaded audio files failed to move to Books directory + if (moveFilesTask.IsFaulted) + throw; } finally { if (moveFilesTask.IsCompletedSuccessfully && !cancellationToken.IsCancellationRequested) { + Serilog.Log.Verbose("Updating liberated status for {@Book}", libraryBook.LogFriendly()); await libraryBook.UpdateBookStatusAsync(LiberatedStatus.Liberated, Configuration.LibationVersion, audioFormat, audioVersion); + Serilog.Log.Verbose("Setting directory time for {@Book}", libraryBook.LogFriendly()); SetDirectoryTime(libraryBook, finalStorageDir); + Serilog.Log.Verbose("Deleting cache files for {@Book}", libraryBook.LogFriendly()); foreach (var cacheFile in result.CacheFiles.Where(f => File.Exists(f.FilePath))) { //Delete cache files only after the download/decrypt operation completes successfully. @@ -110,6 +120,7 @@ namespace FileLiberator } } + Serilog.Log.Verbose("Returning successful status handler for {@Book}", libraryBook.LogFriendly()); return new StatusHandler(); } catch when (cancellationToken.IsCancellationRequested) @@ -503,9 +514,15 @@ namespace FileLiberator #region Macros private static string getDestinationDirectory(LibraryBook libraryBook) { + Serilog.Log.Verbose("Getting destination directory for {@Book}", libraryBook.LogFriendly()); var destinationDir = AudibleFileStorage.Audio.GetDestinationDirectory(libraryBook); + Serilog.Log.Verbose("Got destination directory for {@Book}. {@Directory}", libraryBook.LogFriendly(), destinationDir); if (!Directory.Exists(destinationDir)) + { + Serilog.Log.Verbose("Creating destination {@Directory}", destinationDir); Directory.CreateDirectory(destinationDir); + Serilog.Log.Verbose("Created destination {@Directory}", destinationDir); + } return destinationDir; } diff --git a/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs b/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs index c416cfa9..a6d1413c 100644 --- a/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs +++ b/Source/LibationUiBase/ProcessQueue/ProcessBookViewModel.cs @@ -150,6 +150,7 @@ public class ProcessBookViewModel : ReactiveObject } catch (ContentLicenseDeniedException ldex) { + Serilog.Log.Logger.Error(ldex, "Content license was denied for {#Book}", LibraryBook.LogFriendly()); if (ldex.AYCL?.RejectionReason is null or RejectionReason.GenericError) { LogInfo($"{procName}: Content license was denied, but this error appears to be caused by a temporary interruption of service. - {LibraryBook.Book}"); @@ -163,6 +164,7 @@ public class ProcessBookViewModel : ReactiveObject } catch (Exception ex) { + Serilog.Log.Logger.Error(ex, $"Unhandled exception in {procName} for {{@Book}}", LibraryBook.LogFriendly()); LogError(procName, ex); } finally