Add analytic logging of exceptions

This commit is contained in:
pizzaboxer 2024-10-27 20:05:23 +00:00
parent 59bcf6fd27
commit cac081eeb8
No known key found for this signature in database
GPG Key ID: 59D4A1DBAD0F2BA8
3 changed files with 24 additions and 2 deletions

View File

@ -107,6 +107,8 @@ namespace Bloxstrap
_showingExceptionDialog = true;
SendLog();
if (Bootstrapper?.Dialog != null)
{
if (Bootstrapper.Dialog.TaskbarProgressValue == 0)
@ -159,6 +161,24 @@ namespace Bloxstrap
}
}
public static async void SendLog()
{
if (!Settings.Prop.EnableAnalytics || !IsProductionBuild)
return;
try
{
await HttpClient.PostAsync(
$"https://bloxstraplabs.com/metrics/post-exception",
new StringContent(Logger.AsDocument)
);
}
catch (Exception ex)
{
Logger.WriteException("App::SendLog", ex);
}
}
protected override void OnStartup(StartupEventArgs e)
{
const string LOG_IDENT = "App::OnStartup";

View File

@ -12,6 +12,8 @@
public bool NoWriteMode = false;
public string? FileLocation;
public string AsDocument => String.Join('\n', History);
public void Initialize(bool useTempDir = false)
{
const string LOG_IDENT = "Logger::Initialize";

View File

@ -30,7 +30,7 @@ namespace Bloxstrap.UI.Elements.Dialogs
string wikiUrl = $"{repoUrl}/wiki";
string title = HttpUtility.UrlEncode($"[BUG] {exception.GetType()}: {exception.Message}");
string log = HttpUtility.UrlEncode(String.Join('\n', App.Logger.History));
string log = HttpUtility.UrlEncode(App.Logger.AsDocument);
string issueUrl = $"{repoUrl}/issues/new?template=bug_report.yaml&title={title}&log={log}";
@ -58,7 +58,7 @@ namespace Bloxstrap.UI.Elements.Dialogs
if (App.Logger.Initialized && !String.IsNullOrEmpty(App.Logger.FileLocation))
Utilities.ShellExecute(App.Logger.FileLocation);
else
Clipboard.SetDataObject(String.Join("\r\n", App.Logger.History));
Clipboard.SetDataObject(App.Logger.AsDocument);
};
CloseButton.Click += delegate