@@ -28,9 +28,18 @@ public AnalysisMiddleware(RequestDelegate next, DiagnosticSource diagnosticSourc
28
28
29
29
public async Task Invoke ( HttpContext httpContext )
30
30
{
31
+ var startTimestamp = Stopwatch . GetTimestamp ( ) ;
31
32
if ( _diagnostics . IsEnabled ( "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting" ) )
32
33
{
33
- _diagnostics . Write ( "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting" , new { name = _middlewareName , httpContext = httpContext , instanceId = _instanceId } ) ;
34
+ _diagnostics . Write (
35
+ "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting" ,
36
+ new
37
+ {
38
+ name = _middlewareName ,
39
+ httpContext = httpContext ,
40
+ instanceId = _instanceId ,
41
+ timestamp = startTimestamp ,
42
+ } ) ;
34
43
}
35
44
36
45
try
@@ -39,14 +48,35 @@ public async Task Invoke(HttpContext httpContext)
39
48
40
49
if ( _diagnostics . IsEnabled ( "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished" ) )
41
50
{
42
- _diagnostics . Write ( "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished" , new { name = _middlewareName , httpContext = httpContext , instanceId = _instanceId } ) ;
51
+ var currentTimestamp = Stopwatch . GetTimestamp ( ) ;
52
+ _diagnostics . Write (
53
+ "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished" ,
54
+ new
55
+ {
56
+ name = _middlewareName ,
57
+ httpContext = httpContext ,
58
+ instanceId = _instanceId ,
59
+ timestamp = currentTimestamp ,
60
+ duration = currentTimestamp - startTimestamp ,
61
+ } ) ;
43
62
}
44
63
}
45
64
catch ( Exception ex )
46
65
{
47
66
if ( _diagnostics . IsEnabled ( "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException" ) )
48
67
{
49
- _diagnostics . Write ( "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException" , new { name = _middlewareName , httpContext = httpContext , instanceId = _instanceId , exception = ex } ) ;
68
+ var currentTimestamp = Stopwatch . GetTimestamp ( ) ;
69
+ _diagnostics . Write (
70
+ "Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException" ,
71
+ new
72
+ {
73
+ name = _middlewareName ,
74
+ httpContext = httpContext ,
75
+ instanceId = _instanceId ,
76
+ timestamp = currentTimestamp ,
77
+ duration = currentTimestamp - startTimestamp ,
78
+ exception = ex ,
79
+ } ) ;
50
80
}
51
81
throw ;
52
82
}
0 commit comments