@@ -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>
@@ -70,6 +71,20 @@ void WriteVersion(
70
71
void WriteStart (
71
72
[ System . Runtime . CompilerServices . CallerFilePath ] string filePath = "" ,
72
73
[ System . Runtime . CompilerServices . CallerLineNumber ] int lineNumber = 0 ) ;
74
+
75
+ /// <summary>
76
+ /// Writes exit code and execution time to trace writer.
77
+ /// </summary>
78
+ /// <param name="code">Application exit code.</param>
79
+ /// <param name="filePath">Path of the file this method is called from.</param>
80
+ /// <param name="lineNumber">Line number of file this method is called from.</param>
81
+ [ System . Diagnostics . CodeAnalysis . SuppressMessage ( "Microsoft.Design" , "CA1026:DefaultParametersShouldNotBeUsed" ) ]
82
+ void WriteExit (
83
+ int code ,
84
+ [ System . Runtime . CompilerServices . CallerFilePath ]
85
+ string filePath = "" ,
86
+ [ System . Runtime . CompilerServices . CallerLineNumber ]
87
+ int lineNumber = 0 ) ;
73
88
}
74
89
75
90
public class Trace2 : DisposableObject , ITrace2
@@ -177,6 +192,25 @@ public void WriteStart(
177
192
} ) ;
178
193
}
179
194
195
+ public void WriteExit (
196
+ int code ,
197
+ string filePath = "" ,
198
+ int lineNumber = 0 )
199
+ {
200
+ EnsureArgument . NotNull ( code , nameof ( code ) ) ;
201
+
202
+ WriteMessage ( new ExitCollectorMessage ( )
203
+ {
204
+ Event = Event . Exit ,
205
+ Sid = _sid ,
206
+ Time = DateTime . UtcNow . ToString ( "o" ) ,
207
+ File = filePath ,
208
+ Line = lineNumber ,
209
+ Code = code ,
210
+ ElapsedTime = DateTimeOffset . UtcNow . ToUnixTimeMicroseconds ( ) - _applicationStartTime
211
+ } ) ;
212
+ }
213
+
180
214
private void WriteMessage ( CollectorMessage message )
181
215
{
182
216
ThrowIfDisposed ( ) ;
@@ -253,3 +287,18 @@ public override string ToJson()
253
287
new StringEnumConverter ( new CamelCaseNamingStrategy ( ) ) ) ;
254
288
}
255
289
}
290
+
291
+ public class ExitCollectorMessage : CollectorMessage
292
+ {
293
+ [ JsonProperty ( "t_abs" ) ]
294
+ public long ElapsedTime { get ; set ; }
295
+
296
+ [ JsonProperty ( "code" ) ]
297
+ public int Code { get ; set ; }
298
+
299
+ public override string ToJson ( )
300
+ {
301
+ return JsonConvert . SerializeObject ( this ,
302
+ new StringEnumConverter ( new CamelCaseNamingStrategy ( ) ) ) ;
303
+ }
304
+ }
0 commit comments