From 3341fed0bf1cd6c0e52ae6eed5269af249b781e9 Mon Sep 17 00:00:00 2001 From: ngelsi Date: Tue, 17 Aug 2021 16:43:09 +0200 Subject: [PATCH] Serilog logging of exceptions for troubleshooting current errors --- .vscode/launch.json | 26 ++++++++++ .vscode/tasks.json | 42 +++++++++++++++ TsukiTag/App.axaml.cs | 18 +++++-- TsukiTag/Converters/BitmapConverter.cs | 6 ++- .../DbRepository.OnlineListPicture.cs | 24 ++++++--- .../DbRepository.ThumbnailStorage.cs | 7 +-- .../DbRepository.WorkspacePicture.cs | 13 +++-- .../OnlinePictureProviderElement.cs | 9 +++- TsukiTag/Dependencies/PictureControl.cs | 46 +++++++++------- TsukiTag/Dependencies/PictureWorker.cs | 52 +++++++++++-------- .../DanbooruPictureProvider.cs | 7 ++- .../KonachanPictureProvider.cs | 7 ++- .../YanderePictureProvider.cs | 7 ++- TsukiTag/Program.cs | 26 +++++++++- TsukiTag/TsukiTag.csproj | 4 ++ TsukiTag/ViewModels/SettingsViewModel.cs | 2 + .../ViewModelCollectionHandlerBase.cs | 31 +++++++---- TsukiTag/Views/PictureDetail.axaml | 2 +- 18 files changed, 249 insertions(+), 80 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..a8df9ba --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/TsukiTag/bin/Debug/net5.0/TsukiTag.dll", + "args": [], + "cwd": "${workspaceFolder}/TsukiTag", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach" + } + ] +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..4745170 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,42 @@ +{ + "version": "2.0.0", + "tasks": [ + { + "label": "build", + "command": "dotnet", + "type": "process", + "args": [ + "build", + "${workspaceFolder}/TsukiTag/TsukiTag.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "publish", + "command": "dotnet", + "type": "process", + "args": [ + "publish", + "${workspaceFolder}/TsukiTag/TsukiTag.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + }, + { + "label": "watch", + "command": "dotnet", + "type": "process", + "args": [ + "watch", + "run", + "${workspaceFolder}/TsukiTag/TsukiTag.csproj", + "/property:GenerateFullPaths=true", + "/consoleloggerparameters:NoSummary" + ], + "problemMatcher": "$msCompile" + } + ] +} \ No newline at end of file diff --git a/TsukiTag/App.axaml.cs b/TsukiTag/App.axaml.cs index fe9106f..3d06b18 100644 --- a/TsukiTag/App.axaml.cs +++ b/TsukiTag/App.axaml.cs @@ -3,6 +3,7 @@ using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; using ReactiveUI; +using Serilog; using System; using System.Reactive; using TsukiTag.ViewModels; @@ -16,7 +17,7 @@ public class App : Application public override void Initialize() { - AvaloniaXamlLoader.Load(this); + AvaloniaXamlLoader.Load(this); } public override void OnFrameworkInitializationCompleted() @@ -30,11 +31,22 @@ public override void OnFrameworkInitializationCompleted() Ioc.SimpleIoc.NotificationControl )); - MainWindow = desktop.MainWindow; + MainWindow = desktop.MainWindow; } - RxApp.DefaultExceptionHandler = Observer.Create(Console.WriteLine); + RxApp.DefaultExceptionHandler = Observer.Create((ex) => + { + Log.Error(ex, "General unhandled exception catched"); + }); + + AppDomain.CurrentDomain.UnhandledException += OnUnhandledException; + base.OnFrameworkInitializationCompleted(); } + + private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Log.Error(e.ExceptionObject as Exception, "General unhandled exception catched"); + } } } diff --git a/TsukiTag/Converters/BitmapConverter.cs b/TsukiTag/Converters/BitmapConverter.cs index bdf02dd..519c849 100644 --- a/TsukiTag/Converters/BitmapConverter.cs +++ b/TsukiTag/Converters/BitmapConverter.cs @@ -2,6 +2,7 @@ using Avalonia.Data.Converters; using Avalonia.Media.Imaging; using Avalonia.Platform; +using Serilog; using System; using System.Collections.Generic; using System.Globalization; @@ -49,7 +50,10 @@ public object Convert(object value, Type targetType, object parameter, CultureIn pic = Ioc.SimpleIoc.PictureDownloader.DownloadBitmap(picture.Url).GetAwaiter().GetResult(); } } - catch { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while downloading bitmap for image", picture); + } return pic; diff --git a/TsukiTag/Dependencies/DbRepository.OnlineListPicture.cs b/TsukiTag/Dependencies/DbRepository.OnlineListPicture.cs index 76283fa..ff777b2 100644 --- a/TsukiTag/Dependencies/DbRepository.OnlineListPicture.cs +++ b/TsukiTag/Dependencies/DbRepository.OnlineListPicture.cs @@ -1,4 +1,5 @@ using LiteDB; +using Serilog; using System; using System.Collections.Generic; using System.IO; @@ -91,12 +92,13 @@ public List GetAllForFilter(ProviderFilter filter) while (items.Count <= ((filter.Page + 1) * filter.Limit)) { var item = allItems.ElementAtOrDefault(i); - if(item == null) + if (item == null) { break; } - if (item != null && item.Picture.TagList.Any(t => tagsToSearch.Any(tt => t.WildcardMatches(tt)))) { + if (item != null && item.Picture.TagList.Any(t => tagsToSearch.Any(tt => t.WildcardMatches(tt)))) + { items.Add(item); } @@ -123,8 +125,9 @@ public List GetAllForFilter(ProviderFilter filter) return items; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, "Error occurred while retrieving online list pictures for filter", filter); return new List(); } } @@ -150,8 +153,9 @@ public List GetAllForPicture(string md5) return items; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, "Error occurred while retrieving all online list pictures for MD5", md5); return new List(); } } @@ -220,8 +224,9 @@ public bool AddToList(Guid resourceListId, Picture picture) return false; } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Could not add picture to online list {resourceListId}", picture); return false; } } @@ -250,8 +255,9 @@ public bool RemoveFromAllLists(Picture picture) return true; } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Could not remove picture from online lists", picture); return false; } } @@ -279,8 +285,9 @@ public bool RemoveFromList(Guid resourceListId, Picture picture) return true; } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Could not remove picture from online list {resourceListId}", picture); return false; } } @@ -337,8 +344,9 @@ private bool AddToLists(Picture picture, List lists) return true; } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Could not add picture to specific online lists", picture); return false; } } diff --git a/TsukiTag/Dependencies/DbRepository.ThumbnailStorage.cs b/TsukiTag/Dependencies/DbRepository.ThumbnailStorage.cs index f7f6ca4..18ed628 100644 --- a/TsukiTag/Dependencies/DbRepository.ThumbnailStorage.cs +++ b/TsukiTag/Dependencies/DbRepository.ThumbnailStorage.cs @@ -1,5 +1,6 @@ using Avalonia.Media.Imaging; using LiteDB; +using Serilog; using System; using System.Collections.Generic; using System.IO; @@ -85,13 +86,13 @@ public void AddOrUpdateThumbnail(string md5, Bitmap bitmap) { return; } - + storage.Upload(md5, md5, ms); } } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Exception happened while adding or updating bitmap thumbnail for hash {md5}"); } finally { diff --git a/TsukiTag/Dependencies/DbRepository.WorkspacePicture.cs b/TsukiTag/Dependencies/DbRepository.WorkspacePicture.cs index 4219382..132f770 100644 --- a/TsukiTag/Dependencies/DbRepository.WorkspacePicture.cs +++ b/TsukiTag/Dependencies/DbRepository.WorkspacePicture.cs @@ -1,5 +1,6 @@ using Avalonia.Media.Imaging; using LiteDB; +using Serilog; using System; using System.Collections.Generic; using System.IO; @@ -120,8 +121,9 @@ public List GetAllForFilter(ProviderFilter filter) return items; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, "Error occurred while getting workspace pictures for filter", filter); return new List(); } } @@ -148,8 +150,9 @@ public List GetAllForPicture(string md5) return allItems; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Error occurred while getting all workspace pictures for hash {md5}"); return new List(); } } @@ -210,8 +213,9 @@ public bool AddToWorkspace(Guid resourceListId, Picture picture, string filePath return false; } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Could not add picture to workspace {resourceListId} with file path {filePath}", picture); return false; } } @@ -239,8 +243,9 @@ public bool RemoveFromWorkspace(Guid resourceListId, Picture picture) return true; } - catch (Exception) + catch (Exception ex) { + Log.Error($"Could not remove picture from workspace {resourceListId}", picture); return false; } } diff --git a/TsukiTag/Dependencies/OnlinePictureProviderElement.cs b/TsukiTag/Dependencies/OnlinePictureProviderElement.cs index 77012c0..83bbc22 100644 --- a/TsukiTag/Dependencies/OnlinePictureProviderElement.cs +++ b/TsukiTag/Dependencies/OnlinePictureProviderElement.cs @@ -1,4 +1,5 @@ using RestSharp; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -48,7 +49,9 @@ public virtual async Task GetPicture(string id) } } catch (Exception ex) - { } + { + Log.Error(ex, $"Error occured while getting picture from online provider {Provider} with ID {id}"); + } return null; } @@ -83,11 +86,15 @@ public virtual async Task GetPictures(ProviderFilterElement filt result.ProviderEnd = true; result.ErrorCode = "ToastProviderError"; + Log.Warning($"Non-OK status code {response?.StatusCode} received from provider {Provider} to filter.", filter); + OnNonOkResultReceived(response, filter, result); } } catch (Exception ex) { + Log.Error(ex, $"Exception occurred during picture retrieval from provider {Provider} to filter.", filter); + result.Succeeded = false; result.ErrorCode = "ToastProviderError"; } diff --git a/TsukiTag/Dependencies/PictureControl.cs b/TsukiTag/Dependencies/PictureControl.cs index 31286dc..b32274e 100644 --- a/TsukiTag/Dependencies/PictureControl.cs +++ b/TsukiTag/Dependencies/PictureControl.cs @@ -1,4 +1,5 @@ -using System; +using Serilog; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; @@ -73,7 +74,7 @@ public class PictureControl : IPictureControl private List openedPictures; - private HashSet seenPictures; + private HashSet seenPictures; private Guid pictureContext; @@ -129,7 +130,10 @@ public async void SelectPicture(Picture picture) PictureSelected?.Invoke(this, picture); } } - catch { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while selecting picture", picture); + } finally { semaphoreSlim.Release(); @@ -174,13 +178,10 @@ public async Task PictureInContext(Picture picture) { return await Task.FromResult(picture.PictureContext == pictureContext); } - catch { } finally { semaphoreSlim.Release(); } - - return await Task.FromResult(false); } public async void DeselectPicture(Picture picture) @@ -195,7 +196,10 @@ public async void DeselectPicture(Picture picture) PictureDeselected?.Invoke(this, picture); } - catch { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while de-selecting picture", picture); + } finally { semaphoreSlim.Release(); @@ -208,13 +212,16 @@ public async Task OpenPicture(Picture picture) try { var bitmap = await this.pictureDownloadControl.DownloadBitmap(picture); - if(bitmap != null) + if (bitmap != null) { openedPictures.Add(picture); PictureOpened?.Invoke(this, new PictureOpenedEventArgs(picture, bitmap)); } } - catch { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while opening picture", picture); + } finally { semaphoreSlim.Release(); @@ -233,7 +240,10 @@ public async Task OpenPictureInBackground(Picture picture) PictureOpenedInBackground?.Invoke(this, new PictureOpenedEventArgs(picture, bitmap)); } } - catch { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while opening picture in background", picture); + } finally { semaphoreSlim.Release(); @@ -272,9 +282,9 @@ public async Task AddPicture(Picture picture) PictureAdded?.Invoke(this, picture); } } - catch + catch (Exception ex) { - + Log.Error(ex, $"Error occurred while downloading thumbnail and adding picture to current collection", picture); } finally { @@ -285,8 +295,9 @@ public async Task AddPicture(Picture picture) } } } - catch + catch (Exception ex) { + Log.Error(ex, $"Error occurred while checking picture existence before downloading and adding to current collection", picture); } } @@ -319,8 +330,6 @@ public async Task ResetPictures() currentPictureSet = new List(); seenPictures = new HashSet(); } - catch(Exception) - {} finally { semaphoreSlim.Release(); @@ -336,7 +345,6 @@ public async Task SwitchPictureContext() { pictureContext = Guid.NewGuid(); } - catch { } finally { semaphoreSlim.Release(); @@ -350,7 +358,6 @@ public async Task GetPictureContext() { return await Task.FromResult(pictureContext); } - catch { } finally { semaphoreSlim.Release(); @@ -366,7 +373,10 @@ public async Task GetTags() { return await Task.FromResult(currentTagCollection); } - catch { } + catch (Exception ex) + { + Log.Error(ex, "Exception occurred while getting current tag collection"); + } finally { semaphoreSlim.Release(); diff --git a/TsukiTag/Dependencies/PictureWorker.cs b/TsukiTag/Dependencies/PictureWorker.cs index 55ff0d7..92885b1 100644 --- a/TsukiTag/Dependencies/PictureWorker.cs +++ b/TsukiTag/Dependencies/PictureWorker.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Media.Imaging; using ExifLibrary; +using Serilog; using System; using System.Collections.Generic; using System.Diagnostics; @@ -97,7 +98,10 @@ IPictureDownloader pictureDownloader picture.Tags = string.Join(" ", tagProperty.Value.ToString()?.Split(';').Select(s => s.Trim())); } } - catch { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while retrieving EXIF tags from picture", picture); + } } using (var ms2 = new MemoryStream(ResizeImage(systemBitmap, picture.PreviewWidth, picture.PreviewHeight))) @@ -109,20 +113,22 @@ IPictureDownloader pictureDownloader tuple.Picture = picture; ms.Position = 0; - tuple.Image = new Bitmap(ms); + tuple.Image = new Bitmap(ms); systemBitmap.Dispose(); return tuple; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Error occurred while processing image metadata for local image from {imagePath}"); return null; } }); } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Error occurred while processing image metadata for local image from {imagePath}"); return null; } } @@ -148,12 +154,12 @@ await Task.Run(async () => { image = await this.pictureDownloader.DownloadBitmap(picture.DownloadUrl); } - + if (image == null) { image = await this.pictureDownloader.DownloadBitmap(picture.Url); } - + if (image != null) { var temporaryFile = Path.Combine(Path.GetTempPath(), $"{picture.Md5}.{picture.Extension}"); @@ -175,15 +181,15 @@ await Task.Run(async () => }); } } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Error occurred while opening picture in default application", picture); } }); } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Error occurred while opening picture in default application", picture); } } @@ -207,9 +213,9 @@ public async Task GetPictureWebsiteUrl(Picture picture) return url; } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Error occurred while re-constructing picture website URL", picture); } return null; @@ -232,9 +238,9 @@ await Task.Run(async () => }); } } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Error occurred while opening picture in web browser", picture); } }); } @@ -251,9 +257,9 @@ await Task.Run(async () => await Application.Current.Clipboard.SetTextAsync(url); } } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Error occurred while copying picture website URL to clipboard", picture); } }); } @@ -267,9 +273,9 @@ public async Task DeletePicture(WorkspacePicture picture, Workspace workspace) File.Delete(picture.FilePath); } } - catch (Exception) + catch (Exception ex) { - + Log.Error(ex, $"Could not delete picture physical file at {picture?.FilePath}"); } } @@ -293,7 +299,7 @@ public async Task SaveWorkspacePicture(Picture picture, Workspace worksp workingImage = await this.pictureDownloader.DownloadBitmap(picture.DownloadUrl); } } - + if (workingImage == null) { if (!string.IsNullOrEmpty(picture.FileUrl)) @@ -369,14 +375,16 @@ public async Task SaveWorkspacePicture(Picture picture, Workspace worksp } } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Error occurred while saving picture to workspace {workspace?.Id}", picture); return null; } }); } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Error occurred while saving picture to workspace {workspace?.Id}", picture); return null; } } @@ -429,7 +437,7 @@ private string GetMD5HashFromFile(byte[] data) public Bitmap ClonePicture(Bitmap picture) { - if(picture != null) + if (picture != null) { using (var ms = new MemoryStream()) { diff --git a/TsukiTag/Dependencies/ProviderSpecific/DanbooruPictureProvider.cs b/TsukiTag/Dependencies/ProviderSpecific/DanbooruPictureProvider.cs index 10ecde6..49001c9 100644 --- a/TsukiTag/Dependencies/ProviderSpecific/DanbooruPictureProvider.cs +++ b/TsukiTag/Dependencies/ProviderSpecific/DanbooruPictureProvider.cs @@ -1,6 +1,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RestSharp; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -99,8 +100,10 @@ public override Task> TransformRawData(ProviderFilterElement? filt } } } - catch - { } + catch(Exception ex) + { + Log.Error(ex, $"Error occurred while transforming raw response data for {Provider} for filter", filter); + } return Task.FromResult(pictures); } diff --git a/TsukiTag/Dependencies/ProviderSpecific/KonachanPictureProvider.cs b/TsukiTag/Dependencies/ProviderSpecific/KonachanPictureProvider.cs index 349ca6d..6a27ce6 100644 --- a/TsukiTag/Dependencies/ProviderSpecific/KonachanPictureProvider.cs +++ b/TsukiTag/Dependencies/ProviderSpecific/KonachanPictureProvider.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -100,8 +101,10 @@ public override Task> TransformRawData(ProviderFilterElement? filt } } } - catch - { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while transforming raw response data for {Provider} for filter", filter); + } return Task.FromResult(pictures); } diff --git a/TsukiTag/Dependencies/ProviderSpecific/YanderePictureProvider.cs b/TsukiTag/Dependencies/ProviderSpecific/YanderePictureProvider.cs index 6e41124..6ca40e8 100644 --- a/TsukiTag/Dependencies/ProviderSpecific/YanderePictureProvider.cs +++ b/TsukiTag/Dependencies/ProviderSpecific/YanderePictureProvider.cs @@ -1,5 +1,6 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using Serilog; using System; using System.Collections.Generic; using System.Linq; @@ -100,8 +101,10 @@ public override Task> TransformRawData(ProviderFilterElement? filt } } } - catch - { } + catch (Exception ex) + { + Log.Error(ex, $"Error occurred while transforming raw response data for {Provider} for filter", filter); + } return Task.FromResult(pictures); } diff --git a/TsukiTag/Program.cs b/TsukiTag/Program.cs index 535c841..7f27c8c 100644 --- a/TsukiTag/Program.cs +++ b/TsukiTag/Program.cs @@ -3,7 +3,9 @@ using Avalonia.ReactiveUI; using Projektanker.Icons.Avalonia; using Projektanker.Icons.Avalonia.FontAwesome; +using Serilog; using System; +using System.IO; namespace TsukiTag { @@ -18,14 +20,34 @@ public static void Main(string[] args) => BuildAvaloniaApp() // Avalonia configuration, don't remove; also used by visual designer. public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() - .AfterSetup(AfterSetupCallback) + .AfterSetup(AfterSetupCallback) .UsePlatformDetect() - .LogToTrace() + .LogToTrace() .UseReactiveUI(); private static void AfterSetupCallback(AppBuilder appBuilder) + { + SetUpFontAwesome(); + SetUpLogging(); + } + + private static void SetUpFontAwesome() { IconProvider.Register(); } + + private static void SetUpLogging() + { + var logPath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TsukiTag", "logs"); + if (!Directory.Exists(logPath)) + { + Directory.CreateDirectory(logPath); + } + + Log.Logger = new LoggerConfiguration() + .WriteTo.Console(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Debug) + .WriteTo.File(Path.Combine(logPath, "log-.txt"), restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information, rollingInterval: RollingInterval.Day, fileSizeLimitBytes: (1024*1024), rollOnFileSizeLimit: true, retainedFileCountLimit: 5, outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] {Message:lj}{NewLine}{Exception}{NewLine}{Properties:j}") + .CreateLogger(); + } } } diff --git a/TsukiTag/TsukiTag.csproj b/TsukiTag/TsukiTag.csproj index bce46d0..abab3b2 100644 --- a/TsukiTag/TsukiTag.csproj +++ b/TsukiTag/TsukiTag.csproj @@ -53,6 +53,10 @@ + + + + diff --git a/TsukiTag/ViewModels/SettingsViewModel.cs b/TsukiTag/ViewModels/SettingsViewModel.cs index 72567e0..9f06af0 100644 --- a/TsukiTag/ViewModels/SettingsViewModel.cs +++ b/TsukiTag/ViewModels/SettingsViewModel.cs @@ -1,5 +1,6 @@ using LiteDB; using ReactiveUI; +using Serilog; using System; using System.Collections.Generic; using System.Collections.ObjectModel; @@ -149,6 +150,7 @@ public async void OnSettingsSaved() } catch (Exception ex) { + Log.Error(ex, $"Exception occurred while saving settings"); this.notificationControl.SendToastMessage(ToastMessage.Closeable(Language.SettingsSaveError)); } }); diff --git a/TsukiTag/ViewModels/ViewModelCollectionHandlerBase.cs b/TsukiTag/ViewModels/ViewModelCollectionHandlerBase.cs index 93aef42..a6e18bd 100644 --- a/TsukiTag/ViewModels/ViewModelCollectionHandlerBase.cs +++ b/TsukiTag/ViewModels/ViewModelCollectionHandlerBase.cs @@ -11,6 +11,7 @@ using System.Collections.ObjectModel; using TsukiTag.Models.Repository; using Avalonia.Media.Imaging; +using Serilog; namespace TsukiTag.ViewModels { @@ -57,7 +58,7 @@ IPictureProviderContext providerContext public virtual void Reinitialize() { - } + } protected async Task OnOpenInDefaultApplication(Picture picture) { @@ -322,6 +323,8 @@ protected async Task OnAddToSpecificWorkspace(Guid id, Picture picture, Bi } else { + Log.Warning($"Picture worker returned falsely for adding picture to workspace {id}", picture); + if (notify) { await this.notificationControl.SendToastMessage(ToastMessage.Closeable(Language.ActionGenericError, "workspace")); @@ -350,6 +353,8 @@ await Task.Run(async () => } else { + Log.Warning($"Picture worker returned falsely for adding picture to online list {id}", picture); + if (notify) { await this.notificationControl.SendToastMessage(ToastMessage.Closeable(Language.ActionGenericError)); @@ -427,7 +432,7 @@ protected async Task OnAddToWorkspaces(List workspaces, Picture } if (!await OnAddToSpecificWorkspace(workspace.Id, picture, image, false, false)) - { + { if (notify) { await this.notificationControl.SendToastMessage(ToastMessage.Closeable(Language.ToastWorkspaceProcessError, "workspace")); @@ -476,8 +481,9 @@ protected async Task OnSaveChanges(Picture picture, Bitmap? image = null, return false; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, "Exception occurred while saving changes to picture", picture); return false; } }); @@ -491,17 +497,17 @@ protected async Task OnRedownloadPicture(Picture picture, bool notify = tr { if (!string.IsNullOrEmpty(picture.Id) && !string.IsNullOrEmpty(picture.Provider)) { - if(notify) + if (notify) { await this.notificationControl.SendToastMessage(ToastMessage.Uncloseable(string.Format(Language.ToastRedownloading, picture.Id, picture.Provider), "redownload")); } var newPicture = await this.providerContext.RedownloadPicture(picture); - if(newPicture != null) + if (newPicture != null) { picture.UpdateGenericMetadata(newPicture); - if(notify) + if (notify) { await this.notificationControl.SendToastMessage(ToastMessage.Closeable(string.Format(Language.ToastRedownloadedSingle, picture.Id, picture.Provider), "redownload")); } @@ -510,10 +516,10 @@ protected async Task OnRedownloadPicture(Picture picture, bool notify = tr } else { - if(notify) + if (notify) { await this.notificationControl.SendToastMessage(ToastMessage.Closeable(string.Format(Language.ToastRedownloadCouldNotFind, picture.Id, picture.Provider), "redownload")); - } + } return false; } @@ -528,8 +534,9 @@ protected async Task OnRedownloadPicture(Picture picture, bool notify = tr return false; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, "Exception occurred while re-downloading picture", picture); } if (notify) @@ -566,14 +573,16 @@ protected async Task OnApplyMetadataGroup(Guid id, Picture picture, bool n { if (notify) { - await this.notificationControl.SendToastMessage(ToastMessage.Closeable(Language.ToastNotLocal, "metadatagroup")); + await this.notificationControl.SendToastMessage(ToastMessage.Closeable(Language.ToastNotLocal, "metadatagroup")); } return false; } } - catch (Exception) + catch (Exception ex) { + Log.Error(ex, $"Exception occurred while applying metadata group {id} to picture", picture); + } if (notify) diff --git a/TsukiTag/Views/PictureDetail.axaml b/TsukiTag/Views/PictureDetail.axaml index b175991..6ab903a 100644 --- a/TsukiTag/Views/PictureDetail.axaml +++ b/TsukiTag/Views/PictureDetail.axaml @@ -35,7 +35,7 @@ - +