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

Commit

Permalink
Rename tickCount to timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Jan 8, 2016
1 parent 84d80eb commit bd7532a
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Microsoft.AspNet.Hosting/Internal/HostingApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,41 +33,50 @@ public HostingApplication(
public Context CreateContext(IFeatureCollection contextFeatures)
{
var httpContext = _httpContextFactory.Create(contextFeatures);
var startTick = _logger.IsEnabled(LogLevel.Information) ? Stopwatch.GetTimestamp() : 0;
var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest");
var startTimestamp = (diagnoticsEnabled || _logger.IsEnabled(LogLevel.Information)) ? Stopwatch.GetTimestamp() : 0;

var scope = _logger.RequestScope(httpContext);
_logger.RequestStarting(httpContext);
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.BeginRequest"))
if (diagnoticsEnabled)
{
_diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext, tickCount = startTick });
_diagnosticSource.Write("Microsoft.AspNet.Hosting.BeginRequest", new { httpContext = httpContext, timestamp = startTimestamp });
}

return new Context
{
HttpContext = httpContext,
Scope = scope,
StartTimestamp = startTick,
StartTimestamp = startTimestamp,
};
}

public void DisposeContext(Context context, Exception exception)
{
var httpContext = context.HttpContext;
var currentTimestamp = context.StartTimestamp != 0 ? Stopwatch.GetTimestamp() : 0;
_logger.RequestFinished(httpContext, context.StartTimestamp, currentTimestamp);

if (exception == null)
{
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest"))
var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.EndRequest");
var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0;

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

if (diagnoticsEnabled)
{
_diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext, tickCount = currentTimestamp });
_diagnosticSource.Write("Microsoft.AspNet.Hosting.EndRequest", new { httpContext = httpContext, timestamp = currentTimestamp });
}
}
else
{
if (_diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException"))
var diagnoticsEnabled = _diagnosticSource.IsEnabled("Microsoft.AspNet.Hosting.UnhandledException");
var currentTimestamp = (diagnoticsEnabled || context.StartTimestamp != 0) ? Stopwatch.GetTimestamp() : 0;

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

if (diagnoticsEnabled)
{
_diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, tickCount = currentTimestamp, exception = exception });
_diagnosticSource.Write("Microsoft.AspNet.Hosting.UnhandledException", new { httpContext = httpContext, timestamp = currentTimestamp, exception = exception });
}
}

Expand Down

0 comments on commit bd7532a

Please sign in to comment.