diff --git a/Bloxstrap/App.xaml.cs b/Bloxstrap/App.xaml.cs index 7542ed4..5dced57 100644 --- a/Bloxstrap/App.xaml.cs +++ b/Bloxstrap/App.xaml.cs @@ -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"; diff --git a/Bloxstrap/Logger.cs b/Bloxstrap/Logger.cs index ff6db1a..884e077 100644 --- a/Bloxstrap/Logger.cs +++ b/Bloxstrap/Logger.cs @@ -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"; diff --git a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs index 9301fdf..d1d9411 100644 --- a/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs +++ b/Bloxstrap/UI/Elements/Dialogs/ExceptionDialog.xaml.cs @@ -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