7
7
'
8
8
' This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY
9
9
10
+ Imports System.Globalization
10
11
Imports System.IO
12
+ Imports System.Text.RegularExpressions
11
13
Imports Microsoft.VisualBasic.ApplicationServices
12
14
Imports Newtonsoft.Json
13
15
Imports WinNUT_Client_Common
@@ -20,23 +22,31 @@ Namespace My
20
22
' StartupNextInstance : Déclenché lors du lancement d'une application à instance unique et si cette application est déjà active.
21
23
' NetworkAvailabilityChanged : Déclenché quand la connexion réseau est connectée ou déconnectée.
22
24
Partial Friend Class MyApplication
25
+ ' Default culture for output so logs can be shared with the project.
26
+ Private Shared DEF_CULTURE_INFO As CultureInfo = CultureInfo.InvariantCulture
23
27
24
28
25
29
Private CrashBug_Form As New Form
26
30
Private BtnClose As New Button
27
31
Private BtnGenerate As New Button
28
32
Private Msg_Crash As New Label
29
33
Private Msg_Error As New TextBox
30
- Private exception As Exception
34
+
35
+ Private crashReportData As String
31
36
32
37
Private Sub MyApplication_Startup(sender As Object , e As StartupEventArgs) Handles Me .Startup
38
+ ' Uncomment below and comment out Handles line for _UnhandledException sub when debugging unhandled exceptions.
39
+ ' AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomainUnhandledException
33
40
Init_Globals()
34
41
LogFile.LogTracing( "MyApplication_Startup complete." , LogLvl.LOG_DEBUG, Me )
35
42
End Sub
36
43
37
- Private Sub MyApplication_UnhandledException( ByVal sender As Object , ByVal e As UnhandledExceptionEventArgs) Handles Me .UnhandledException
44
+ Private Sub AppDomainUnhandledException(sender As Object , e As System.UnhandledExceptionEventArgs)
45
+ MyApplication_UnhandledException(sender, New UnhandledExceptionEventArgs( False , e.ExceptionObject))
46
+ End Sub
47
+
48
+ Private Sub MyApplication_UnhandledException(sender As Object , e As UnhandledExceptionEventArgs) Handles Me .UnhandledException
38
49
e.ExitApplication = False
39
- exception = e.Exception
40
50
41
51
With Msg_Crash
42
52
.Location = New Point( 6 , 6 )
@@ -87,6 +97,8 @@ Namespace My
87
97
.Controls.Add(BtnGenerate)
88
98
End With
89
99
100
+ crashReportData = GenerateCrashReport(e.Exception)
101
+
90
102
AddHandler BtnClose.Click, AddressOf Application.Close_Button_Click
91
103
AddHandler BtnGenerate.Click, AddressOf Application.Generate_Button_Click
92
104
@@ -96,9 +108,13 @@ Namespace My
96
108
End Sub
97
109
98
110
Private Shared Function GenerateCrashReport(ex As Exception) As String
99
- Dim reportStream As New StringWriter()
111
+ Dim jsonSerializerSettings As New JsonSerializerSettings()
112
+ jsonSerializerSettings.Culture = DEF_CULTURE_INFO
113
+ jsonSerializerSettings.Formatting = Formatting.Indented
114
+
115
+ Dim reportStream As New StringWriter(DEF_CULTURE_INFO)
100
116
reportStream.WriteLine( "WinNUT Bug Report" )
101
- reportStream.WriteLine( "Generated at " + DateTime .UtcNow.ToString("F" ))
117
+ reportStream.WriteLine( "Generated at " + Date .UtcNow.ToString( "F" , DEF_CULTURE_INFO ))
102
118
reportStream.WriteLine()
103
119
reportStream.WriteLine( "OS Version: " & Computer.Info.OSVersion)
104
120
reportStream.WriteLine( "WinNUT Version: " & ProgramVersion)
@@ -124,7 +140,7 @@ Namespace My
124
140
confCopy.Add(kvp.Key, newVal)
125
141
Next
126
142
127
- reportStream.WriteLine(JsonConvert.SerializeObject(confCopy, Formatting.Indented ))
143
+ reportStream.WriteLine(JsonConvert.SerializeObject(confCopy, jsonSerializerSettings ))
128
144
reportStream.WriteLine()
129
145
Else
130
146
reportStream.WriteLine( "[EMPTY]" )
@@ -134,28 +150,27 @@ Namespace My
134
150
# Region "Exceptions"
135
151
reportStream.WriteLine( "==== Exception ====" )
136
152
reportStream.WriteLine()
137
- reportStream.WriteLine(JsonConvert.SerializeObject(ex, Formatting.Indented ))
153
+ reportStream.WriteLine(Regex.Unescape( JsonConvert.SerializeObject(ex, jsonSerializerSettings) ))
138
154
reportStream.WriteLine()
139
155
# End Region
140
156
141
157
reportStream.WriteLine( "==== Last Events ====" )
142
158
143
159
LogFile.LastEvents.Reverse()
144
160
reportStream.WriteLine()
145
- reportStream.WriteLine(JsonConvert.SerializeObject(LogFile.LastEvents, Formatting.Indented ))
161
+ reportStream.WriteLine(Regex.Unescape( JsonConvert.SerializeObject(LogFile.LastEvents, jsonSerializerSettings) ))
146
162
147
163
Return reportStream.ToString()
148
164
End Function
149
165
150
166
Private Sub Generate_Button_Click(sender As Object , e As EventArgs)
151
- Dim logFileName = "CrashReport_" + DateTime.Now.ToString( "s" ).Replace( ":" , "." ) + ".txt"
152
- Dim report = GenerateCrashReport(exception)
167
+ Dim logFileName = "CrashReport_" + Date .Now.ToString( "s" ).Replace( ":" , "." ) + ".txt"
153
168
154
- Computer.Clipboard.SetText(report )
169
+ Computer.Clipboard.SetText(crashReportData )
155
170
156
171
Directory.CreateDirectory(TEMP_DATA_PATH)
157
172
Dim CrashLog_Report = New StreamWriter(Path.Combine(TEMP_DATA_PATH, logFileName))
158
- CrashLog_Report.WriteLine(report )
173
+ CrashLog_Report.WriteLine(crashReportData )
159
174
CrashLog_Report.Close()
160
175
161
176
' Open an Explorer window to the crash log.
0 commit comments