/// <summary> /// Logs an HTTP response. /// </summary> /// <param name="responseInfo">The response information.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponse(ResponseInfo responseInfo, ISet <string> fieldsToMask, TraceFormatter formatter) { this.responseInfo = responseInfo; this.isFailure = !string.IsNullOrEmpty(responseInfo.ErrorMessage); LogResponseDetails(responseInfo, fieldsToMask, formatter); }
/// <summary> /// Gets the request summary for logging. /// </summary> /// <param name="headers">The HTTP request headers.</param> /// <param name="body">The HTTP request body.</param> /// <param name="headersToMask">The set of headers to mask</param> /// <param name="formatter">The formatter to use for masking</param> /// <returns>The request summary for logging.</returns> private string GetRequestSummary(WebHeaderCollection headers, string body, ISet <string> headersToMask, TraceFormatter formatter) { Dictionary <string, string> maskedHeader = MaskHeaders(headers, headersToMask); NameValueCollection collection = HttpUtility.ParseQueryString(body); string loggedHeaders = GetFormattedHttpHeaderLogs(maskedHeader, ", "); string details = formatter.MaskContents(body, headersToMask); return(loggedHeaders + details); }
/// <summary> /// Logs the details of an HTTP response. /// </summary> /// <param name="responseInfo">The response information.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponseDetails(ResponseInfo responseInfo, ISet <string> fieldsToMask, TraceFormatter formatter) { if (config.MaskCredentials) { this.DetailedResponseLog = GetFormattedResponseLog(responseInfo, fieldsToMask, formatter); } else { this.DetailedResponseLog = GetFormattedResponseLog(responseInfo); } }
/// <summary> /// Logs the details of an HTTP response. /// </summary> /// <param name="response">The HTTP web response.</param> /// <param name="isFailure">True, if this is a failed response, false /// otherwise.</param> /// <param name="responseBody">The response body.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponseDetails(WebResponse response, string responseBody, ISet <string> fieldsToMask, TraceFormatter formatter) { if (config.MaskCredentials) { this.DetailedResponseLog = GetFormattedResponseLog(new ResponseInfo( response.Headers, responseBody), fieldsToMask, formatter); } else { this.DetailedResponseLog = GetFormattedResponseLog(new ResponseInfo( response.Headers, responseBody)); } }
/// <summary> /// Gets the trace formatter for formatting an HTTP request. /// </summary> /// <param name="shouldMask">True, if fields should be masked, false /// otherwise.</param> /// <returns>A trace formatter for formatting HTTP request.</returns> private TraceFormatter GetTraceFormatterForHTTPRequests(bool shouldMask) { TraceFormatter formatter = null; if (shouldMask) { formatter = new UrlEncodedBodyFormatter(); } else { formatter = new DefaultBodyFormatter(); } return(formatter); }
/// <summary> /// Gets the formatted logs for an HTTP response. /// </summary> /// <param name="responseInfo">The response information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="traceFormatter">The trace formatter to use when formatting /// the message.</param> /// <returns>The response log text.</returns> private string GetFormattedResponseLog(ResponseInfo responseInfo, ISet <string> headersToMask, TraceFormatter traceFormatter) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("\r\nResponse\r\n"); builder.AppendFormat("--------\r\n"); builder.AppendFormat("\r\n{0}\r\n\r\n{1}\r\n", GetFormattedHttpHeaderLogs(MaskHeaders(responseInfo.Headers, headersToMask), "\r\n"), traceFormatter.MaskContents(responseInfo.Body, headersToMask)); builder.AppendFormat("-----------------END API CALL-----------------------\r\n"); return(builder.ToString()); }
/// <summary> /// Logs the details of an HTTP response. /// </summary> /// <param name="response">The HTTP web response.</param> /// <param name="responseBody">The response body.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponseDetails(WebResponse response, string responseBody, ISet <string> fieldsToMask, TraceFormatter formatter) { WebHeaderCollection collection = (response == null) ? new WebHeaderCollection() : response.Headers; if (config.MaskCredentials) { this.DetailedResponseLog = GetFormattedResponseLog(new ResponseInfo( collection, responseBody), fieldsToMask, formatter); } else { this.DetailedResponseLog = GetFormattedResponseLog(new ResponseInfo( collection, responseBody)); } }
/// <summary> /// Gets the formatted logs for an HTTP request. /// </summary> /// <param name="requestInfo">The request information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="traceFormatter">The trace formatter to use when formatting /// the message.</param> /// <returns></returns> private string GetFormattedRequestLog(RequestInfo requestInfo, ISet <string> headersToMask, TraceFormatter traceFormatter) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("\r\n-----------------BEGIN API CALL---------------------\r\n"); builder.AppendFormat("\r\nRequest\r\n"); builder.AppendFormat("-------\r\n\r\n"); StringBuilder headerBuilder = new StringBuilder(); headerBuilder.AppendFormat("{0} {1}\r\n", requestInfo.Method, requestInfo.Uri.AbsolutePath); headerBuilder.AppendFormat("{0}", GetFormattedHttpHeaderLogs(MaskHeaders( requestInfo.Headers, headersToMask), "\r\n")); builder.AppendFormat("{0}\r\n\r\n{1}\r\n", headerBuilder.ToString(), traceFormatter.MaskContents(requestInfo.Body, headersToMask)); return(builder.ToString()); }
/// <summary> /// Logs an HTTP response. /// </summary> /// <param name="response">The HTTP web response.</param> /// <param name="isFailure">True, if this is a failed response, false /// otherwise.</param> /// <param name="responseBody">The response body.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponse(WebResponse response, bool isFailure, string responseBody, ISet <string> fieldsToMask, TraceFormatter formatter) { LogResponseSummary(isFailure, ""); LogResponseDetails(response, responseBody, fieldsToMask, formatter); }
/// <summary> /// Logs the summary of an HTTP request. /// </summary> /// <param name="request">The HTTP web request.</param> /// <param name="requestBody">The request body.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> public void LogRequestSummary(WebRequest request, string requestBody, ISet <string> headersToMask, TraceFormatter formatter) { LogRequestSummary(request, GetRequestSummary(request.Headers, requestBody, headersToMask, formatter)); }
/// <summary> /// Gets the formatted logs for an HTTP request. /// </summary> /// <param name="requestInfo">The request information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="traceFormatter">The trace formatter to use when formatting /// the message.</param> /// <returns></returns> private string GetFormattedRequestLog(RequestInfo requestInfo, ISet<string> headersToMask, TraceFormatter traceFormatter) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("\r\n-----------------BEGIN API CALL---------------------\r\n"); builder.AppendFormat("\r\nRequest\r\n"); builder.AppendFormat("-------\r\n\r\n"); StringBuilder headerBuilder = new StringBuilder(); headerBuilder.AppendFormat("{0} {1}\r\n", requestInfo.Method, requestInfo.Uri.AbsolutePath); headerBuilder.AppendFormat("{0}", GetFormattedHttpHeaderLogs(MaskHeaders( requestInfo.Headers, headersToMask), "\r\n")); builder.AppendFormat("{0}\r\n\r\n{1}\r\n", headerBuilder.ToString(), traceFormatter.MaskContents(requestInfo.Body, headersToMask)); return builder.ToString(); }
/// <summary> /// Logs an HTTP request. /// </summary> /// <param name="requestInfo">The request information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> /// <returns>The request logs</returns> public void LogRequest(RequestInfo requestInfo, ISet <string> headersToMask, TraceFormatter formatter) { this.requestInfo = requestInfo; this.DetailedRequestLog = GetFormattedRequestLog(requestInfo, headersToMask, formatter); }
/// <summary> /// Logs an HTTP response. /// </summary> /// <param name="response">The HTTP web response.</param> /// <param name="isFailure">True, if this is a failed response, false /// otherwise.</param> /// <param name="responseBody">The response body.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponse(WebResponse response, bool isFailure, string responseBody, ISet<string> fieldsToMask, TraceFormatter formatter) { LogResponseSummary(isFailure, ""); LogResponseDetails(response, responseBody, fieldsToMask, formatter); }
/// <summary> /// Logs an HTTP response. /// </summary> /// <param name="responseInfo">The response information.</param> /// <param name="isFailure">True, if this is a failed response, false /// otherwise.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponse(ResponseInfo responseInfo, bool isFailure, ISet <string> fieldsToMask, TraceFormatter formatter) { LogResponseSummary(isFailure, ""); LogResponseDetails(responseInfo, fieldsToMask, formatter); }
/// <summary> /// Logs the summary of an HTTP request. /// </summary> /// <param name="requestInfo">The request information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> public void LogRequestSummary(RequestInfo requestInfo, ISet <string> headersToMask, TraceFormatter formatter) { LogRequestSummary(requestInfo, GetRequestSummary(requestInfo.Headers, requestInfo.Body, headersToMask, formatter)); }
/// <summary> /// Logs an HTTP request. /// </summary> /// <param name="requestInfo">The request information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> /// <returns>The request logs</returns> public void LogRequest(RequestInfo requestInfo, ISet <string> headersToMask, TraceFormatter formatter) { LogRequestSummary(requestInfo, headersToMask, formatter); LogRequestDetails(requestInfo, headersToMask, formatter); }
/// <summary> /// Gets the request summary for logging. /// </summary> /// <param name="headers">The HTTP request headers.</param> /// <param name="body">The HTTP request body.</param> /// <returns>The request summary for logging.</returns> private string GetRequestSummary(WebHeaderCollection headers, string body, ISet<string> headersToMask, TraceFormatter formatter) { Dictionary<string, string> maskedHeader = MaskHeaders(headers, headersToMask); NameValueCollection collection = HttpUtility.ParseQueryString(body); string loggedHeaders = GetFormattedHttpHeaderLogs(maskedHeader, ", "); string details = formatter.MaskContents(body, headersToMask); return loggedHeaders + details; }
/// <summary> /// Gets the formatted logs for an HTTP response. /// </summary> /// <param name="responseInfo">The response information.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="bodyFormatter">The trace formatter to use when formatting /// the message. /// <returns>The response log text.</returns> private string GetFormattedResponseLog(ResponseInfo responseInfo, ISet<string> headersToMask, TraceFormatter traceFormatter) { StringBuilder builder = new StringBuilder(); builder.AppendFormat("\r\nResponse\r\n"); builder.AppendFormat("--------\r\n"); builder.AppendFormat("\r\n{0}\r\n\r\n{1}\r\n", GetFormattedHttpHeaderLogs(MaskHeaders(responseInfo.Headers, headersToMask), "\r\n"), traceFormatter.MaskContents(responseInfo.Body, headersToMask)); builder.AppendFormat("-----------------END API CALL-----------------------\r\n"); return builder.ToString(); }
/// <summary> /// Logs the details of an HTTP request. /// </summary> /// <param name="request">The HTTP web request.</param> /// <param name="requestBody">The request body.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> public void LogRequestDetails(WebRequest request, string requestBody, ISet<string> headersToMask, TraceFormatter formatter) { this.DetailedRequestLog = GetFormattedRequestLog(new RequestInfo(request, requestBody), headersToMask, formatter); }
/// <summary> /// Logs an HTTP request. /// </summary> /// <param name="requestInfo">The request information.</param> /// <param name="headersToMask">The headers to mask.</param> public void LogRequest(RequestInfo requestInfo, ISet <string> headersToMask) { TraceFormatter formatter = GetTraceFormatterForHTTPRequests(config.MaskCredentials); LogRequest(requestInfo, headersToMask, formatter); }
/// <summary> /// Logs an HTTP request. /// </summary> /// <param name="request">The HTTP web request.</param> /// <param name="requestBody">The request body.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> /// <returns>The request logs</returns> public void LogRequest(WebRequest request, string requestBody, ISet <string> headersToMask, TraceFormatter formatter) { LogRequestSummary(request, requestBody, headersToMask, formatter); LogRequestDetails(request, requestBody, headersToMask, formatter); }
/// <summary> /// Logs the summary of an HTTP request. /// </summary> /// <param name="request">The HTTP web request.</param> /// <param name="requestBody">The request body.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> public void LogRequestSummary(WebRequest request, string requestBody, ISet<string> headersToMask, TraceFormatter formatter) { LogRequestSummary(request, GetRequestSummary(request.Headers, requestBody, headersToMask, formatter)); }
/// <summary> /// Logs the details of an HTTP request. /// </summary> /// <param name="request">The HTTP web request.</param> /// <param name="requestBody">The request body.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> public void LogRequestDetails(WebRequest request, string requestBody, ISet <string> headersToMask, TraceFormatter formatter) { this.DetailedRequestLog = GetFormattedRequestLog(new RequestInfo(request, requestBody), headersToMask, formatter); }
/// <summary> /// Logs an HTTP request. /// </summary> /// <param name="request">The HTTP web request.</param> /// <param name="requestBody">The request body.</param> /// <param name="headersToMask">The headers to mask.</param> /// <param name="formatter">The <see cref="TraceFormatter"/> to use when /// formatting the message.</param> /// <returns>The request logs</returns> public void LogRequest(WebRequest request, string requestBody, ISet<string> headersToMask, TraceFormatter formatter) { LogRequestSummary(request, requestBody, headersToMask, formatter); LogRequestDetails(request, requestBody, headersToMask, formatter); }
/// <summary> /// Logs the details of an HTTP response. /// </summary> /// <param name="response">The HTTP web response.</param> /// <param name="isFailure">True, if this is a failed response, false /// otherwise.</param> /// <param name="responseBody">The response body.</param> /// <param name="fieldsToMask">The list of fields to mask.</param> /// <param name="formatter">The formatter to be used for formatting the /// response logs.</param> public void LogResponseDetails(WebResponse response, string responseBody, ISet<string> fieldsToMask, TraceFormatter formatter) { if (config.MaskCredentials) { this.DetailedResponseLog = GetFormattedResponseLog(new ResponseInfo( response.Headers, responseBody), fieldsToMask, formatter); } else { this.DetailedResponseLog = GetFormattedResponseLog(new ResponseInfo( response.Headers, responseBody)); } }