Skip to content

Commit

Permalink
sentry(Configuration): Add configuration file when app crash
Browse files Browse the repository at this point in the history
  • Loading branch information
Belphemur committed May 9, 2021
1 parent 8205809 commit e5a4140
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions SoundSwitch/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Sentry;
using Serilog;
using SoundSwitch.Framework;
using SoundSwitch.Framework.Configuration;
using SoundSwitch.Framework.Logger.Configuration;
using SoundSwitch.Framework.NotificationManager;
using SoundSwitch.Framework.WinApi;
Expand Down Expand Up @@ -80,7 +81,6 @@ private static void Main()
Application.SetHighDpiMode(HighDpiMode.PerMonitorV2);
#endif
Application.SetCompatibleTextRenderingDefault(false);

// Manage the Closing events send by Windows
// Since this app don't use a Form as "main window" the app doesn't close
// when it should without this.
Expand All @@ -106,20 +106,20 @@ private static void Main()
try
{
#endif
MMNotificationClient.Instance.Register();
MMNotificationClient.Instance.Register();


using var ctx = new WindowsFormsSynchronizationContext();
using var ctx = new WindowsFormsSynchronizationContext();

SynchronizationContext.SetSynchronizationContext(ctx);
try
{
Application.Run(new SoundSwitchApplicationContext());
}
finally
{
SynchronizationContext.SetSynchronizationContext(null);
}
SynchronizationContext.SetSynchronizationContext(ctx);
try
{
Application.Run(new SoundSwitchApplicationContext());
}
finally
{
SynchronizationContext.SetSynchronizationContext(null);
}


#if !DEBUG
Expand Down Expand Up @@ -172,7 +172,14 @@ private static void HandleException(Exception exception)
{
if (exception == null)
return;
var eventId = SentrySdk.CaptureException(exception);

SentryId eventId = default;
SentrySdk.WithScope(scope =>
{
scope.AddAttachment(AppConfigs.Configuration.FileLocation);
eventId = SentrySdk.CaptureException(exception);
}
);

var exceptionMessage = exception.Message;
if (exception.InnerException != null)
Expand Down

0 comments on commit e5a4140

Please sign in to comment.