@@ -15,7 +15,8 @@ namespace GitCredentialManager;
15
15
public enum Event
16
16
{
17
17
Version = 0 ,
18
- Start = 1
18
+ Start = 1 ,
19
+ Exit = 2
19
20
}
20
21
21
22
/// <summary>
@@ -77,6 +78,22 @@ void WriteStart(
77
78
long elapsedTime ,
78
79
[ System . Runtime . CompilerServices . CallerFilePath ] string filePath = "" ,
79
80
[ System . Runtime . CompilerServices . CallerLineNumber ] int lineNumber = 0 ) ;
81
+
82
+ /// <summary>
83
+ /// Writes exit code and execution time to trace writer.
84
+ /// </summary>
85
+ /// <param name="code">Application exit code.</param>
86
+ /// <param name="timeInMilliseconds">Elapsed time in milliseconds since GCM started.</param>
87
+ /// <param name="filePath">Path of the file this method is called from.</param>
88
+ /// <param name="lineNumber">Line number of file this method is called from.</param>
89
+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Design" , "CA1026:DefaultParametersShouldNotBeUsed" ) ]
90
+ void WriteExit (
91
+ int code ,
92
+ long elapsedTime ,
93
+ [ System . Runtime . CompilerServices . CallerFilePath ]
94
+ string filePath = "" ,
95
+ [ System . Runtime . CompilerServices . CallerLineNumber ]
96
+ int lineNumber = 0 ) ;
80
97
}
81
98
82
99
public class Trace2 : DisposableObject , ITrace2
@@ -186,6 +203,26 @@ public void WriteStart(
186
203
} ) ;
187
204
}
188
205
206
+ public void WriteExit (
207
+ int code ,
208
+ long elapsedTime ,
209
+ string filePath = "" ,
210
+ int lineNumber = 0 )
211
+ {
212
+ EnsureArgument . NotNull ( code , nameof ( code ) ) ;
213
+
214
+ WriteMessage ( new ExitCollectorMessage ( )
215
+ {
216
+ Event = Event . Exit ,
217
+ Sid = _sid ,
218
+ Time = DateTime . UtcNow . ToString ( "o" ) ,
219
+ File = filePath ,
220
+ Line = lineNumber ,
221
+ Code = code ,
222
+ ElapsedTime = elapsedTime
223
+ } ) ;
224
+ }
225
+
189
226
private void WriteMessage ( CollectorMessage message )
190
227
{
191
228
ThrowIfDisposed ( ) ;
@@ -262,3 +299,18 @@ public override string ToJson()
262
299
new StringEnumConverter ( new CamelCaseNamingStrategy ( ) ) ) ;
263
300
}
264
301
}
302
+
303
+ public class ExitCollectorMessage : CollectorMessage
304
+ {
305
+ [ JsonProperty ( "t_abs" ) ]
306
+ public long ElapsedTime { get ; set ; }
307
+
308
+ [ JsonProperty ( "code" ) ]
309
+ public int Code { get ; set ; }
310
+
311
+ public override string ToJson ( )
312
+ {
313
+ return JsonConvert . SerializeObject ( this ,
314
+ new StringEnumConverter ( new CamelCaseNamingStrategy ( ) ) ) ;
315
+ }
316
+ }
0 commit comments