From ebaeb63c9460b46b02adbd9451444329a8a41702 Mon Sep 17 00:00:00 2001 From: bao-qian Date: Fri, 1 May 2020 01:33:32 +0800 Subject: [PATCH 1/2] add crash report --- Wox.Infrastructure/Logger/Log.cs | 5 ++++- Wox.Infrastructure/Wox.Infrastructure.csproj | 3 +++ Wox/App.xaml.cs | 8 ++++---- Wox/Helper/ErrorReporting.cs | 8 ++++++-- Wox/ViewModel/MainViewModel.cs | 2 +- Wox/Wox.csproj | 3 +++ 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 11a6d2a8e..7d88cd57b 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -2,9 +2,11 @@ using System.Diagnostics; using System.IO; using System.Runtime.CompilerServices; +using Mindscape.Raygun4Net; using NLog; using NLog.Config; using NLog.Targets; +using Sentry; using Wox.Infrastructure.Exception; using Wox.Infrastructure.UserSettings; @@ -13,7 +15,7 @@ namespace Wox.Infrastructure.Logger public static class Log { public const string DirectoryName = "Logs"; - + private static RaygunClient _raygunClient = new RaygunClient("LG5MX0YYMCpCN2AtD0fdZw"); public static string CurrentLogDirectory { get; } static Log() @@ -73,6 +75,7 @@ public static void WoxError(this NLog.Logger logger, string message, System.Exce { Debug.WriteLine($"ERROR|{logger.Name}|{methodName}|{message}"); logger.Error($"{methodName}|{message}|{ExceptionFormatter.FormattedException(exception)}"); + _raygunClient.Send(exception); #if DEBUG throw exception; #endif diff --git a/Wox.Infrastructure/Wox.Infrastructure.csproj b/Wox.Infrastructure/Wox.Infrastructure.csproj index 53728d8a2..e9cff745f 100644 --- a/Wox.Infrastructure/Wox.Infrastructure.csproj +++ b/Wox.Infrastructure/Wox.Infrastructure.csproj @@ -91,6 +91,9 @@ 1.1.4 + + 5.10.2 + 9.0.1 diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index f7f16fd37..06aacb949 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -22,6 +22,7 @@ using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; using Wox.Infrastructure.Exception; +using Sentry; namespace Wox { @@ -38,7 +39,7 @@ public partial class App : IDisposable, ISingleInstanceApp private readonly Portable _portable = new Portable(); private readonly Alphabet _alphabet = new Alphabet(); private StringMatcher _stringMatcher; - + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private class Options @@ -63,7 +64,6 @@ private void ParseCommandLineArgs(IList args) [STAThread] public static void Main() { - // force english exception message for better github issue Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US"); if (SingleInstance.InitializeAsFirstInstance(Unique)) { @@ -88,10 +88,10 @@ private void OnStartup(object sender, StartupEventArgs e) RegisterAppDomainExceptions(); RegisterDispatcherUnhandledException(); - + //throw new Exception("sentry wox exception"); _portable.PreStartCleanUpAfterPortabilityUpdate(); - + ImageLoader.Initialize(); diff --git a/Wox/Helper/ErrorReporting.cs b/Wox/Helper/ErrorReporting.cs index 704a991ed..5ea282dcc 100644 --- a/Wox/Helper/ErrorReporting.cs +++ b/Wox/Helper/ErrorReporting.cs @@ -2,6 +2,7 @@ using System.Runtime.CompilerServices; using System.Threading.Tasks; using System.Windows.Threading; +using Mindscape.Raygun4Net; using NLog; using Wox.Infrastructure.Exception; @@ -9,6 +10,8 @@ namespace Wox.Helper { public static class ErrorReporting { + private static RaygunClient _raygunClient = new RaygunClient("LG5MX0YYMCpCN2AtD0fdZw"); + private static void Report(Exception e, [CallerMemberName] string method = "") { var logger = LogManager.GetLogger(method); @@ -19,19 +22,20 @@ private static void Report(Exception e, [CallerMemberName] string method = "") public static void UnhandledExceptionHandleTask(Task t) { - //handle non-ui sub task exceptions + _raygunClient.Send(t.Exception); Report(t.Exception); } public static void UnhandledExceptionHandleMain(object sender, UnhandledExceptionEventArgs e) { + _raygunClient.Send(e.ExceptionObject as Exception); //handle non-ui main thread exceptions Report((Exception)e.ExceptionObject); } public static void DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) { - //handle ui thread exceptions + _raygunClient.Send(e.Exception); Report(e.Exception); //prevent application exist, so the user can copy prompted error info e.Handled = true; diff --git a/Wox/ViewModel/MainViewModel.cs b/Wox/ViewModel/MainViewModel.cs index 8143fb8fd..95aa09ab7 100644 --- a/Wox/ViewModel/MainViewModel.cs +++ b/Wox/ViewModel/MainViewModel.cs @@ -490,7 +490,7 @@ private void QueryResults() return; } _resultsQueue.Add(new ResultsForUpdate(results, plugin.Metadata, query, token, countdown)); - }, token); + }, token).ContinueWith(ErrorReporting.UnhandledExceptionHandleTask, TaskContinuationOptions.OnlyOnFaulted); } Task.Run(() => diff --git a/Wox/Wox.csproj b/Wox/Wox.csproj index f162a9db0..c5dcb41a9 100644 --- a/Wox/Wox.csproj +++ b/Wox/Wox.csproj @@ -484,6 +484,9 @@ 10.3.0 + + 5.10.2 + 9.0.1 From e1937df8072d052a5498c168aae2c748cf9b7bec Mon Sep 17 00:00:00 2001 From: bao-qian Date: Fri, 1 May 2020 01:35:19 +0800 Subject: [PATCH 2/2] fixup --- Wox.Infrastructure/Logger/Log.cs | 1 - Wox/App.xaml.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Wox.Infrastructure/Logger/Log.cs b/Wox.Infrastructure/Logger/Log.cs index 7d88cd57b..90f6406f4 100644 --- a/Wox.Infrastructure/Logger/Log.cs +++ b/Wox.Infrastructure/Logger/Log.cs @@ -6,7 +6,6 @@ using NLog; using NLog.Config; using NLog.Targets; -using Sentry; using Wox.Infrastructure.Exception; using Wox.Infrastructure.UserSettings; diff --git a/Wox/App.xaml.cs b/Wox/App.xaml.cs index 06aacb949..be8c2cf1d 100644 --- a/Wox/App.xaml.cs +++ b/Wox/App.xaml.cs @@ -22,7 +22,6 @@ using Wox.ViewModel; using Stopwatch = Wox.Infrastructure.Stopwatch; using Wox.Infrastructure.Exception; -using Sentry; namespace Wox {