Skip to content

Commit

Permalink
Serilog logging of exceptions for troubleshooting current errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ngelsi committed Aug 17, 2021
1 parent b92de35 commit 3341fed
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 80 deletions.
26 changes: 26 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
42 changes: 42 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
18 changes: 15 additions & 3 deletions TsukiTag/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Markup.Xaml;
using ReactiveUI;
using Serilog;
using System;
using System.Reactive;
using TsukiTag.ViewModels;
Expand All @@ -16,7 +17,7 @@ public class App : Application

public override void Initialize()
{
AvaloniaXamlLoader.Load(this);
AvaloniaXamlLoader.Load(this);
}

public override void OnFrameworkInitializationCompleted()
Expand All @@ -30,11 +31,22 @@ public override void OnFrameworkInitializationCompleted()
Ioc.SimpleIoc.NotificationControl
));

MainWindow = desktop.MainWindow;
MainWindow = desktop.MainWindow;
}

RxApp.DefaultExceptionHandler = Observer.Create<Exception>(Console.WriteLine);
RxApp.DefaultExceptionHandler = Observer.Create<Exception>((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");
}
}
}
6 changes: 5 additions & 1 deletion TsukiTag/Converters/BitmapConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Picture>(ex, $"Error occurred while downloading bitmap for image", picture);
}


return pic;
Expand Down
24 changes: 16 additions & 8 deletions TsukiTag/Dependencies/DbRepository.OnlineListPicture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LiteDB;
using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -91,12 +92,13 @@ public List<OnlineListPicture> 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);
}

Expand All @@ -123,8 +125,9 @@ public List<OnlineListPicture> GetAllForFilter(ProviderFilter filter)
return items;
}
}
catch (Exception)
catch (Exception ex)
{
Log.Error<ProviderFilter>(ex, "Error occurred while retrieving online list pictures for filter", filter);
return new List<OnlineListPicture>();
}
}
Expand All @@ -150,8 +153,9 @@ public List<OnlineListPicture> GetAllForPicture(string md5)
return items;
}
}
catch (Exception)
catch (Exception ex)
{
Log.Error<string>(ex, "Error occurred while retrieving all online list pictures for MD5", md5);
return new List<OnlineListPicture>();
}
}
Expand Down Expand Up @@ -220,8 +224,9 @@ public bool AddToList(Guid resourceListId, Picture picture)

return false;
}
catch (Exception)
catch (Exception ex)
{
Log.Error<Picture>(ex, $"Could not add picture to online list {resourceListId}", picture);
return false;
}
}
Expand Down Expand Up @@ -250,8 +255,9 @@ public bool RemoveFromAllLists(Picture picture)
return true;

}
catch (Exception)
catch (Exception ex)
{
Log.Error<Picture>(ex, $"Could not remove picture from online lists", picture);
return false;
}
}
Expand Down Expand Up @@ -279,8 +285,9 @@ public bool RemoveFromList(Guid resourceListId, Picture picture)

return true;
}
catch (Exception)
catch (Exception ex)
{
Log.Error<Picture>(ex, $"Could not remove picture from online list {resourceListId}", picture);
return false;
}
}
Expand Down Expand Up @@ -337,8 +344,9 @@ private bool AddToLists(Picture picture, List<OnlineList> lists)

return true;
}
catch (Exception)
catch (Exception ex)
{
Log.Error<Picture>(ex, $"Could not add picture to specific online lists", picture);
return false;
}
}
Expand Down
7 changes: 4 additions & 3 deletions TsukiTag/Dependencies/DbRepository.ThumbnailStorage.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia.Media.Imaging;
using LiteDB;
using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -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
{
Expand Down
13 changes: 9 additions & 4 deletions TsukiTag/Dependencies/DbRepository.WorkspacePicture.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Avalonia.Media.Imaging;
using LiteDB;
using Serilog;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -120,8 +121,9 @@ public List<WorkspacePicture> GetAllForFilter(ProviderFilter filter)
return items;
}
}
catch (Exception)
catch (Exception ex)
{
Log.Error<ProviderFilter>(ex, "Error occurred while getting workspace pictures for filter", filter);
return new List<WorkspacePicture>();
}
}
Expand All @@ -148,8 +150,9 @@ public List<WorkspacePicture> 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<WorkspacePicture>();
}
}
Expand Down Expand Up @@ -210,8 +213,9 @@ public bool AddToWorkspace(Guid resourceListId, Picture picture, string filePath

return false;
}
catch (Exception)
catch (Exception ex)
{
Log.Error<Picture>(ex, $"Could not add picture to workspace {resourceListId} with file path {filePath}", picture);
return false;
}
}
Expand Down Expand Up @@ -239,8 +243,9 @@ public bool RemoveFromWorkspace(Guid resourceListId, Picture picture)

return true;
}
catch (Exception)
catch (Exception ex)
{
Log.Error<Picture>($"Could not remove picture from workspace {resourceListId}", picture);
return false;
}
}
Expand Down
9 changes: 8 additions & 1 deletion TsukiTag/Dependencies/OnlinePictureProviderElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using RestSharp;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -48,7 +49,9 @@ public virtual async Task<Picture> GetPicture(string id)
}
}
catch (Exception ex)
{ }
{
Log.Error(ex, $"Error occured while getting picture from online provider {Provider} with ID {id}");
}

return null;
}
Expand Down Expand Up @@ -83,11 +86,15 @@ public virtual async Task<ProviderResult> GetPictures(ProviderFilterElement filt
result.ProviderEnd = true;
result.ErrorCode = "ToastProviderError";

Log.Warning<ProviderFilterElement>($"Non-OK status code {response?.StatusCode} received from provider {Provider} to filter.", filter);

OnNonOkResultReceived(response, filter, result);
}
}
catch (Exception ex)
{
Log.Error<ProviderFilterElement>(ex, $"Exception occurred during picture retrieval from provider {Provider} to filter.", filter);

result.Succeeded = false;
result.ErrorCode = "ToastProviderError";
}
Expand Down
Loading

0 comments on commit 3341fed

Please sign in to comment.