コード例 #1
0
 /// <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);
 }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
 /// <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);
     }
 }
コード例 #4
0
 /// <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));
     }
 }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        /// <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());
        }
コード例 #7
0
        /// <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));
            }
        }
コード例 #8
0
        /// <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());
        }
コード例 #9
0
 /// <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);
 }
コード例 #10
0
 /// <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));
 }
コード例 #11
0
    /// <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();
    }
コード例 #12
0
 /// <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);
 }
コード例 #13
0
 /// <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);
 }
コード例 #14
0
 /// <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);
 }
コード例 #15
0
 /// <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));
 }
コード例 #16
0
 /// <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);
 }
コード例 #17
0
    /// <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;
    }
コード例 #18
0
    /// <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();
    }
コード例 #19
0
 /// <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);
 }
コード例 #20
0
        /// <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);
        }
コード例 #21
0
 /// <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);
 }
コード例 #22
0
 /// <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));
 }
コード例 #23
0
 /// <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);
 }
コード例 #24
0
 /// <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);
 }
コード例 #25
0
 /// <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));
   }
 }