Skip to content
This repository was archived by the owner on Dec 8, 2018. It is now read-only.

Commit f387d04

Browse files
avanderhoornkichalla
authored andcommitted
Adds timestamp in accordance with hosting example, as well as duration
1 parent 5ecba20 commit f387d04

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

src/Microsoft.AspNetCore.MiddlewareAnalysis/AnalysisMiddleware.cs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ public AnalysisMiddleware(RequestDelegate next, DiagnosticSource diagnosticSourc
2828

2929
public async Task Invoke(HttpContext httpContext)
3030
{
31+
var startTimestamp = Stopwatch.GetTimestamp();
3132
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareStarting"))
3233
{
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+
});
3443
}
3544

3645
try
@@ -39,14 +48,35 @@ public async Task Invoke(HttpContext httpContext)
3948

4049
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareFinished"))
4150
{
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+
});
4362
}
4463
}
4564
catch (Exception ex)
4665
{
4766
if (_diagnostics.IsEnabled("Microsoft.AspNetCore.MiddlewareAnalysis.MiddlewareException"))
4867
{
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+
});
5080
}
5181
throw;
5282
}

0 commit comments

Comments
 (0)