Skip to content

Commit

Permalink
Merge pull request #2901 from Wox-launcher/bao
Browse files Browse the repository at this point in the history
add crash report
  • Loading branch information
bao-qian committed Apr 30, 2020
2 parents 2f8dc3e + e1937df commit c583f20
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
4 changes: 3 additions & 1 deletion Wox.Infrastructure/Logger/Log.cs
Expand Up @@ -2,6 +2,7 @@
using System.Diagnostics;
using System.IO;
using System.Runtime.CompilerServices;
using Mindscape.Raygun4Net;
using NLog;
using NLog.Config;
using NLog.Targets;
Expand All @@ -13,7 +14,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()
Expand Down Expand Up @@ -73,6 +74,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
Expand Down
3 changes: 3 additions & 0 deletions Wox.Infrastructure/Wox.Infrastructure.csproj
Expand Up @@ -91,6 +91,9 @@
<PackageReference Include="Microsoft-WindowsAPICodePack-Shell">
<Version>1.1.4</Version>
</PackageReference>
<PackageReference Include="Mindscape.Raygun4Net">
<Version>5.10.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
Expand Down
7 changes: 3 additions & 4 deletions Wox/App.xaml.cs
Expand Up @@ -38,7 +38,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
Expand All @@ -63,7 +63,6 @@ private void ParseCommandLineArgs(IList<string> args)
[STAThread]
public static void Main()
{
// force english exception message for better github issue
Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
if (SingleInstance<App>.InitializeAsFirstInstance(Unique))
{
Expand All @@ -88,10 +87,10 @@ private void OnStartup(object sender, StartupEventArgs e)
RegisterAppDomainExceptions();
RegisterDispatcherUnhandledException();
//throw new Exception("sentry wox exception");
_portable.PreStartCleanUpAfterPortabilityUpdate();
ImageLoader.Initialize();
Expand Down
8 changes: 6 additions & 2 deletions Wox/Helper/ErrorReporting.cs
Expand Up @@ -2,13 +2,16 @@
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Threading;
using Mindscape.Raygun4Net;
using NLog;
using Wox.Infrastructure.Exception;

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);
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Wox/ViewModel/MainViewModel.cs
Expand Up @@ -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(() =>
Expand Down
3 changes: 3 additions & 0 deletions Wox/Wox.csproj
Expand Up @@ -484,6 +484,9 @@
<PackageReference Include="JetBrains.Annotations">
<Version>10.3.0</Version>
</PackageReference>
<PackageReference Include="Mindscape.Raygun4Net">
<Version>5.10.2</Version>
</PackageReference>
<PackageReference Include="Newtonsoft.Json">
<Version>9.0.1</Version>
</PackageReference>
Expand Down

0 comments on commit c583f20

Please sign in to comment.