private async Task <HttpResponseMessage> LogResponse(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken, System.Diagnostics.TraceSource fallbackTraceSource, Stopwatch sw) { var response = await base.SendAsync(request, cancellationToken); if (response == null || response.Content == null) { return(response); } var responseContent = await response.Content.ReadAsStringAsync(); try { sw.Stop(); var statusCode = (int)response.StatusCode; var responseHeaders = response.Content.Headers.ToString() + " " + response.Headers.ToString(); responseTraceSource.TraceResponse( (int)response.StatusCode, responseHeaders, responseContent, sw.ElapsedMilliseconds); } catch (Exception exp) { fallbackTraceSource.TraceData(TraceEventType.Error, (int)Event.LoggingExceptionFallingBack, exp); } return(response); }
public void OnActionExecuted(ActionExecutedContext filterContext) { try { var currentRequest = filterContext.HttpContext.Request; if (IsExcluded(currentRequest.Url.ToString())) { return; } var responseTime = GetResponseTime(filterContext); var responseContent = GetModelContent(filterContext); var currentResponse = filterContext.HttpContext.Response; responseTraceSource.TraceResponse( currentResponse.StatusCode, currentResponse.Headers.ToString(), responseContent, responseTime); } catch (Exception exp) { fallbackTraceSource.TraceData(TraceEventType.Error, (int)Event.LoggingExceptionFallingBack, exp); } }