diff --git a/ApplicationServices/UNTESTED/LibraryCommands.cs b/ApplicationServices/UNTESTED/LibraryCommands.cs index aed5f5b9..5b617c4c 100644 --- a/ApplicationServices/UNTESTED/LibraryCommands.cs +++ b/ApplicationServices/UNTESTED/LibraryCommands.cs @@ -9,30 +9,49 @@ namespace ApplicationServices { public static class LibraryCommands { - public static async Task<(int totalCount, int newCount)> IndexLibraryAsync(ILoginCallback callback) + public static async Task<(int totalCount, int newCount)> ImportLibraryAsync(ILoginCallback callback) { - var audibleApiActions = new AudibleApiActions(); - var items = await audibleApiActions.GetAllLibraryItemsAsync(callback); - var totalCount = items.Count; + try + { + var audibleApiActions = new AudibleApiActions(); + var items = await audibleApiActions.GetAllLibraryItemsAsync(callback); + var totalCount = items.Count; + Serilog.Log.Logger.Debug($"GetAllLibraryItems: Total count {totalCount}"); - var libImporter = new LibraryImporter(); - var newCount = await Task.Run(() => libImporter.Import(items)); + var libImporter = new LibraryImporter(); + var newCount = await Task.Run(() => libImporter.Import(items)); + Serilog.Log.Logger.Debug($"Import: New count {newCount}"); - await Task.Run(() => SearchEngineCommands.FullReIndex()); + await Task.Run(() => SearchEngineCommands.FullReIndex()); + Serilog.Log.Logger.Debug("FullReIndex: success"); - return (totalCount, newCount); + return (totalCount, newCount); + } + catch (Exception ex) + { + Serilog.Log.Logger.Error(ex, "Error importing library"); + throw; + } } public static int UpdateTags(this LibationContext context, Book book, string newTags) { - book.UserDefinedItem.Tags = newTags; + try + { + book.UserDefinedItem.Tags = newTags; - var qtyChanges = context.SaveChanges(); + var qtyChanges = context.SaveChanges(); - if (qtyChanges > 0) - SearchEngineCommands.UpdateBookTags(book); + if (qtyChanges > 0) + SearchEngineCommands.UpdateBookTags(book); - return qtyChanges; + return qtyChanges; + } + catch (Exception ex) + { + Serilog.Log.Logger.Error(ex, "Error updating tags"); + throw; + } } } } diff --git a/DataLayer/DataLayer.csproj b/DataLayer/DataLayer.csproj index 9bf98a0a..f5e695a0 100644 --- a/DataLayer/DataLayer.csproj +++ b/DataLayer/DataLayer.csproj @@ -12,13 +12,13 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/DtoImporterService/BookImporter.cs b/DtoImporterService/UNTESTED/BookImporter.cs similarity index 100% rename from DtoImporterService/BookImporter.cs rename to DtoImporterService/UNTESTED/BookImporter.cs diff --git a/DtoImporterService/CategoryImporter.cs b/DtoImporterService/UNTESTED/CategoryImporter.cs similarity index 100% rename from DtoImporterService/CategoryImporter.cs rename to DtoImporterService/UNTESTED/CategoryImporter.cs diff --git a/DtoImporterService/ContributorImporter.cs b/DtoImporterService/UNTESTED/ContributorImporter.cs similarity index 100% rename from DtoImporterService/ContributorImporter.cs rename to DtoImporterService/UNTESTED/ContributorImporter.cs diff --git a/DtoImporterService/ImporterBase.cs b/DtoImporterService/UNTESTED/ImporterBase.cs similarity index 100% rename from DtoImporterService/ImporterBase.cs rename to DtoImporterService/UNTESTED/ImporterBase.cs diff --git a/DtoImporterService/LibraryImporter.cs b/DtoImporterService/UNTESTED/LibraryImporter.cs similarity index 100% rename from DtoImporterService/LibraryImporter.cs rename to DtoImporterService/UNTESTED/LibraryImporter.cs diff --git a/DtoImporterService/SeriesImporter.cs b/DtoImporterService/UNTESTED/SeriesImporter.cs similarity index 100% rename from DtoImporterService/SeriesImporter.cs rename to DtoImporterService/UNTESTED/SeriesImporter.cs diff --git a/FileManager/UNTESTED/FilePathCache.cs b/FileManager/UNTESTED/FilePathCache.cs index bd787360..2a8d9319 100644 --- a/FileManager/UNTESTED/FilePathCache.cs +++ b/FileManager/UNTESTED/FilePathCache.cs @@ -83,9 +83,9 @@ namespace FileManager catch (IOException) { try { resave(); } - catch (IOException) - { - Console.WriteLine("...that's not good"); + catch (IOException ex) + { + Serilog.Log.Logger.Error(ex, "Error saving FilePaths.json"); throw; } } diff --git a/FileManager/UNTESTED/QuickFilters.cs b/FileManager/UNTESTED/QuickFilters.cs index 017c22bd..32c0b41c 100644 --- a/FileManager/UNTESTED/QuickFilters.cs +++ b/FileManager/UNTESTED/QuickFilters.cs @@ -105,12 +105,12 @@ namespace FileManager catch (IOException) { try { resave(); } - catch (IOException) - { - Console.WriteLine("...that's not good"); - throw; - } - } + catch (IOException ex) + { + Serilog.Log.Logger.Error(ex, "Error saving QuickFilters.json"); + throw; + } + } } } } diff --git a/InternalUtilities/UNTESTED/AudibleApiActions.cs b/InternalUtilities/UNTESTED/AudibleApiActions.cs index 35ec6833..8601734d 100644 --- a/InternalUtilities/UNTESTED/AudibleApiActions.cs +++ b/InternalUtilities/UNTESTED/AudibleApiActions.cs @@ -28,7 +28,7 @@ namespace InternalUtilities private async Task> getItemsAsync(ILoginCallback callback) { - var api = await getApiAsync(callback); + var api = await EzApiCreator.GetApiAsync(AudibleApiStorage.IdentityTokensFile, callback, Configuration.Instance.LocaleCountryCode); var items = await AudibleApiExtensions.GetAllLibraryItemsAsync(api); // remove episode parents @@ -62,20 +62,6 @@ namespace InternalUtilities return items; } - private async Task getApiAsync(ILoginCallback callback) - { - try - { - return await EzApiCreator.GetApiAsync(AudibleApiStorage.IdentityTokensFile, callback, Configuration.Instance.LocaleCountryCode); - } - catch (Exception ex) - { - Serilog.Log.Logger.Error(ex, "Error getting Audible API"); - throw; - } - - } - private static List getValidators() { var type = typeof(IValidator); diff --git a/InternalUtilities/UNTESTED/AudibleApiExtensions.cs b/InternalUtilities/UNTESTED/AudibleApiExtensions.cs index b2556a14..0eb02a9d 100644 --- a/InternalUtilities/UNTESTED/AudibleApiExtensions.cs +++ b/InternalUtilities/UNTESTED/AudibleApiExtensions.cs @@ -27,11 +27,11 @@ namespace InternalUtilities ResponseGroups = LibraryOptions.ResponseGroupOptions.ALL_OPTIONS }); - string pageStr = null; + var pageStr = page.ToString(); + LibraryDtoV10 libResult; try { - pageStr = page.ToString(); // important! use this convert method libResult = LibraryDtoV10.FromJson(pageStr); } @@ -43,6 +43,8 @@ namespace InternalUtilities if (!libResult.Items.Any()) break; + else + Serilog.Log.Logger.Debug($"Page {i}: {libResult.Items.Length} results"); allItems.AddRange(libResult.Items); } diff --git a/LibationWinForm/UNTESTED/BookLiberation/AutomatedBackupsForm.cs b/LibationWinForm/UNTESTED/BookLiberation/AutomatedBackupsForm.cs index e3730922..40381fcf 100644 --- a/LibationWinForm/UNTESTED/BookLiberation/AutomatedBackupsForm.cs +++ b/LibationWinForm/UNTESTED/BookLiberation/AutomatedBackupsForm.cs @@ -13,10 +13,20 @@ namespace LibationWinForm.BookLiberation InitializeComponent(); } - public void AppendError(Exception ex) => AppendText("ERROR: " + ex.Message); - public void AppendText(string text) => logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); + public void AppendError(Exception ex) + { + Serilog.Log.Logger.Error(ex, "Automated backup: error"); + appendText("ERROR: " + ex.Message); + } + public void AppendText(string text) + { + Serilog.Log.Logger.Debug($"Automated backup: {text}"); + appendText(text); + } + private void appendText(string text) + => logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")); - public void FinalizeUI() + public void FinalizeUI() { keepGoingCb.Enabled = false; logTb.AppendText(""); diff --git a/LibationWinForm/UNTESTED/BookLiberation/DecryptForm.cs b/LibationWinForm/UNTESTED/BookLiberation/DecryptForm.cs index f3d886d1..242baaef 100644 --- a/LibationWinForm/UNTESTED/BookLiberation/DecryptForm.cs +++ b/LibationWinForm/UNTESTED/BookLiberation/DecryptForm.cs @@ -13,11 +13,10 @@ namespace LibationWinForm.BookLiberation InitializeComponent(); } - System.IO.TextWriter origOut = Console.Out; + System.IO.TextWriter origOut { get; } = Console.Out; private void DecryptForm_Load(object sender, EventArgs e) { // redirect Console.WriteLine to console, textbox - System.IO.TextWriter origOut = Console.Out; var controlWriter = new RichTextBoxTextWriter(this.rtbLog); var multiLogger = new MultiTextWriter(origOut, controlWriter); Console.SetOut(multiLogger); @@ -58,13 +57,19 @@ namespace LibationWinForm.BookLiberation public void SetCoverImage(byte[] coverBytes) => pictureBox1.UIThread(() => pictureBox1.Image = ImageReader.ToImage(coverBytes)); - public static void AppendError(Exception ex) => AppendText("ERROR: " + ex.Message); - public static void AppendText(string text) => - // redirected to log textbox - Console.WriteLine($"{DateTime.Now} {text}") - //logTb.UIThread(() => logTb.AppendText($"{DateTime.Now} {text}{Environment.NewLine}")) - ; + public void AppendError(Exception ex) + { + Serilog.Log.Logger.Error(ex, "Decrypt form: error"); + appendText("ERROR: " + ex.Message); + } + public void AppendText(string text) + { + Serilog.Log.Logger.Debug($"Decrypt form: {text}"); + appendText(text); + } + private void appendText(string text) => Console.WriteLine($"{DateTime.Now} {text}"); - public void UpdateProgress(int percentage) => progressBar1.UIThread(() => progressBar1.Value = percentage); + + public void UpdateProgress(int percentage) => progressBar1.UIThread(() => progressBar1.Value = percentage); } } diff --git a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs index 3773636b..e4a7a0aa 100644 --- a/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs +++ b/LibationWinForm/UNTESTED/Dialogs/IndexLibraryDialog.cs @@ -19,12 +19,11 @@ namespace LibationWinForm { try { - (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.IndexLibraryAsync(new Login.WinformResponder()); + (TotalBooksProcessed, NewBooksAdded) = await LibraryCommands.ImportLibraryAsync(new Login.WinformResponder()); } catch (Exception ex) { - var msg = "Error importing library. Please try again. If this happens after 2 or 3 tries, contact administrator"; - Serilog.Log.Logger.Error(ex, msg); + var msg = "Error importing library. Please try again. If this still happens after 2 or 3 tries, stop and contact administrator"; MessageBox.Show(msg, "Error importing library", MessageBoxButtons.OK, MessageBoxIcon.Error); } diff --git a/LibationWinForm/UNTESTED/Program.cs b/LibationWinForm/UNTESTED/Program.cs index 9c001836..48f8bef7 100644 --- a/LibationWinForm/UNTESTED/Program.cs +++ b/LibationWinForm/UNTESTED/Program.cs @@ -1,5 +1,6 @@ using System; using System.Windows.Forms; +using Dinah.Core.Logging; using Serilog; namespace LibationWinForm @@ -45,11 +46,29 @@ Go to Import > Scan Library private static void init() { + // default. for reference. output example: + // 2019-11-26 08:48:40.224 -05:00 [DBG] Begin Libation + var default_outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}"; + // with class and method info. output example: + // 2019-11-26 08:48:40.224 -05:00 [DBG] (at LibationWinForm.Program.init()) Begin Libation + var code_outputTemplate = "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] (at {Caller}) {Message:lj}{NewLine}{Exception}"; + + var logPath = System.IO.Path.Combine(FileManager.Configuration.Instance.LibationFiles, "Log.log"); + Log.Logger = new LoggerConfiguration() + .Enrich.WithCaller() .MinimumLevel.Debug() - .WriteTo.File(logPath, rollingInterval: RollingInterval.Month) + .WriteTo.File(logPath, + rollingInterval: RollingInterval.Month, + outputTemplate: code_outputTemplate) .CreateLogger(); + + Log.Logger.Debug("Begin Libation"); + + // .Here() captures debug info via System.Runtime.CompilerServices attributes. Warning: expensive + //var withLineNumbers_outputTemplate = "[{Timestamp:HH:mm:ss} {Level}] {SourceContext}{NewLine}{Message}{NewLine}in method {MemberName} at {FilePath}:{LineNumber}{NewLine}{Exception}{NewLine}"; + //Log.Logger.Here().Debug("Begin Libation. Debug with line numbers"); } } } diff --git a/REFERENCE.txt b/REFERENCE.txt index 99c14e0f..b7459b93 100644 --- a/REFERENCE.txt +++ b/REFERENCE.txt @@ -1,6 +1,7 @@ -- begin VERSIONING --------------------------------------------------------------------------------------------------------------------- https://github.com/rmcrackan/Libation/releases +v3.1-beta.6 : Improved logging v3.1-beta.5 : Improved importing v3.1-beta.4 : Added beta-specific logging v3.1-beta.3 : fixed known performance issue: Full-screen grid is slow to respond loading when books aren't liberated