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

Commit 6d2c672

Browse files
committed
updated
1 parent c2749f4 commit 6d2c672

File tree

2 files changed

+17
-36
lines changed

2 files changed

+17
-36
lines changed

src/Microsoft.AspNetCore.Hosting/Internal/HostingApplication.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,11 @@ public void DisposeContext(Context context, Exception exception)
5959
{
6060
var httpContext = context.HttpContext;
6161

62+
long currentTimestamp;
6263
if (exception == null)
6364
{
6465
var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.EndRequest");
65-
var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0;
66+
currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0;
6667

6768
_logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp);
6869

@@ -76,7 +77,7 @@ public void DisposeContext(Context context, Exception exception)
7677
else
7778
{
7879
var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNetCore.Hosting.UnhandledException");
79-
var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0;
80+
currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0;
8081

8182
_logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp);
8283

@@ -88,7 +89,7 @@ public void DisposeContext(Context context, Exception exception)
8889
HostingEventSource.Log.UnhandledException();
8990
}
9091

91-
HostingEventSource.Log.RequestStop();
92+
HostingEventSource.Log.RequestStop(context.StartTimestamp, currentTimestamp);
9293

9394
context.Scope?.Dispose();
9495

src/Microsoft.AspNetCore.Hosting/Internal/HostingEventSource.cs

+13-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Diagnostics.Tracing;
5-
using Microsoft.AspNetCore.Http;
65

76
namespace Microsoft.AspNetCore.Hosting.Internal
87
{
@@ -53,56 +52,37 @@ public void RequestStart(string method, string path)
5352
#if NETSTANDARD1_5
5453
_requestCounter.WriteMetric(1);
5554
#endif
56-
if (IsEnabled())
57-
{
58-
RequestStart(
59-
context.TraceIdentifier,
60-
context.Request.Protocol,
61-
context.Request.Method,
62-
context.Request.ContentType ?? string.Empty,
63-
context.Request.ContentLength.HasValue ? context.Request.ContentLength.Value.ToString() : string.Empty,
64-
context.Request.Scheme,
65-
context.Request.Host.ToString(),
66-
context.Request.PathBase,
67-
context.Request.Path,
68-
context.Request.QueryString.ToString());
69-
}
7055
WriteEvent(3, method, path);
7156
}
7257

73-
[Event(4, Level = EventLevel.Informational)]
74-
public void RequestStop()
58+
[NonEvent]
59+
public void RequestStop(long startTimestamp, long endTimestamp)
7560
{
7661
#if NETSTANDARD1_5
77-
if (exception == null)
78-
{
79-
_successfulRequestCounter.WriteMetric(1);
80-
}
81-
else
82-
{
83-
_failedRequestCounter.WriteMetric(1);
84-
}
62+
_successfulRequestCounter.WriteMetric(1);
8563

8664
if (endTimestamp != 0)
8765
{
8866
_requestExecutionTimeCounter.WriteMetric(endTimestamp - startTimestamp);
8967
}
9068
#endif
91-
if (IsEnabled())
92-
{
93-
RequestStop(
94-
context.Response.StatusCode,
95-
context.Response.ContentType ?? string.Empty,
96-
context.TraceIdentifier,
97-
exception == null ? string.Empty : exception.ToString());
98-
}
69+
RequestStop();
70+
}
71+
72+
[Event(4, Level = EventLevel.Informational)]
73+
private void RequestStop()
74+
{
9975
WriteEvent(4);
10076
}
10177

10278
[Event(5, Level = EventLevel.Error)]
10379
public void UnhandledException()
10480
{
81+
#if NETSTANDARD1_5
82+
_failedRequestCounter.WriteMetric(1);
83+
#endif
10584
WriteEvent(5);
10685
}
86+
10787
}
10888
}

0 commit comments

Comments
 (0)