15
15
16
16
using System ;
17
17
using System . Diagnostics ;
18
- using System . IO ;
19
- using System . IO . Compression ;
20
18
using System . Runtime . ExceptionServices ;
21
19
using System . Runtime . InteropServices ;
22
20
using System . Threading ;
23
21
using System . Windows . Forms ;
22
+ using Sentry ;
24
23
using Serilog ;
25
24
using SoundSwitch . Framework ;
25
+ using SoundSwitch . Framework . Configuration ;
26
26
using SoundSwitch . Framework . Logger . Configuration ;
27
- using SoundSwitch . Framework . Minidump ;
28
27
using SoundSwitch . Framework . NotificationManager ;
29
28
using SoundSwitch . Framework . WinApi ;
30
29
using SoundSwitch . Localization . Factory ;
31
30
using SoundSwitch . Model ;
32
31
using SoundSwitch . Util ;
32
+ using SoundSwitch . Util . Url ;
33
33
34
34
namespace SoundSwitch
35
35
{
@@ -42,13 +42,15 @@ internal static class Program
42
42
[ STAThread ]
43
43
private static void Main ( )
44
44
{
45
+ using var _ = SentrySdk . Init ( options =>
46
+ {
47
+ options . Dsn = "https://[email protected] /5755327" ;
48
+ options . Environment = AssemblyUtils . GetReleaseState ( ) . ToString ( ) ;
49
+ } ) ;
45
50
InitializeLogger ( ) ;
46
51
Log . Information ( "Application Starts" ) ;
47
52
#if ! DEBUG
48
- AppDomain . CurrentDomain . UnhandledException += ( sender , args ) =>
49
- {
50
- HandleException ( ( Exception ) args . ExceptionObject ) ;
51
- } ;
53
+ AppDomain . CurrentDomain . UnhandledException += ( sender , args ) => { HandleException ( ( Exception ) args . ExceptionObject ) ; } ;
52
54
53
55
Log . Information ( "Set Exception Handler" ) ;
54
56
Application . ThreadException += Application_ThreadException ;
@@ -134,7 +136,6 @@ private static void Main()
134
136
WindowsAPIAdapter . Stop ( ) ;
135
137
MMNotificationClient . Instance . Dispose ( ) ;
136
138
Log . CloseAndFlush ( ) ;
137
-
138
139
}
139
140
140
141
/// <summary>
@@ -147,6 +148,8 @@ private static void InitializeLogger()
147
148
$ "{ Application . ProductName } { AssemblyUtils . GetReleaseState ( ) } ({ Application . ProductVersion } )") ;
148
149
Log . Information ( $ "OS: { Environment . OSVersion } ") ;
149
150
Log . Information ( $ "Framework: { Environment . Version } ") ;
151
+
152
+ SentrySdk . ConfigureScope ( scope => { scope . AddAttachment ( AppConfigs . Configuration . FileLocation ) ; } ) ;
150
153
}
151
154
152
155
/// <summary>
@@ -174,8 +177,8 @@ private static void HandleException(Exception exception)
174
177
{
175
178
if ( exception == null )
176
179
return ;
177
- var zipFile = Path . Combine ( ApplicationPath . AppData ,
178
- $ " { Application . ProductName } -crashlog- { DateTime . UtcNow . Date . Day } _ { DateTime . UtcNow . Date . Month } _ { DateTime . UtcNow . Date . Year } .zip" ) ;
180
+ var eventId = SentrySdk . CaptureException ( exception ) ;
181
+
179
182
var exceptionMessage = exception . Message ;
180
183
if ( exception . InnerException != null )
181
184
{
@@ -187,39 +190,15 @@ private static void HandleException(Exception exception)
187
190
188
191
{ exceptionMessage }
189
192
190
- Do you want to save a log of the error that occurred?
191
- This could be useful to fix bugs. Please post this file in the issues section
192
- File Location: { zipFile } " ;
193
+ Would you like to share more information with the developers?" ;
193
194
var result = MessageBox . Show ( message , $@ "{ Application . ProductName } crashed...", MessageBoxButtons . YesNo ,
194
195
MessageBoxIcon . Error ) ;
195
196
196
- if ( result == DialogResult . Yes )
197
- {
198
- using ( new HourGlass ( ) )
199
- {
200
- var fileName = Path . Combine ( ApplicationPath . Default , Environment . MachineName + ".dmp" ) ;
201
- using (
202
- var fs = new FileStream ( fileName , FileMode . Create , FileAccess . ReadWrite ,
203
- FileShare . Write ) )
204
- {
205
- MiniDump . Write ( fs . SafeFileHandle ,
206
- MiniDump . Option . Normal | MiniDump . Option . WithThreadInfo | MiniDump . Option . WithHandleData |
207
- MiniDump . Option . WithDataSegs , MiniDump . ExceptionInfo . Present ) ;
208
- }
209
-
210
- Log . Fatal ( exception , "Exception Occurred " ) ;
211
-
212
- if ( File . Exists ( zipFile ) )
213
- {
214
- File . Delete ( zipFile ) ;
215
- }
216
-
217
- Log . CloseAndFlush ( ) ;
218
-
219
- ZipFile . CreateFromDirectory ( ApplicationPath . Default , zipFile ) ;
220
- }
197
+ if ( result != DialogResult . Yes ) return ;
221
198
222
- Process . Start ( "explorer.exe" , "/select," + @zipFile ) ;
199
+ using ( new HourGlass ( ) )
200
+ {
201
+ BrowserUtil . OpenUrl ( $ "https://soundswitch.aaflalo.me/#sentry?eventId={ eventId } ") ;
223
202
}
224
203
}
225
204
}
0 commit comments