Exemple #1
0
        private static string GetJSONString(ResponseInfo responseInfo)
        {
            char quotes = '"';
            var  json   = new StringBuilder("{" + Environment.NewLine);

            json.Append(String.Format("\t{0}{1}{0} : {0}{2}{0}", quotes, "RequestID", responseInfo.RequestID) + Environment.NewLine);
            json.Append(String.Format("\t{0}{1}{0} : {0}{2}{0}", quotes, "Timestamp", responseInfo.Timestamp.ToString(_defaultDateTimeFormat)) + Environment.NewLine);
            json.Append(String.Format("\t{0}{1}{0} : {0}{2}{0}", quotes, "ContentType", responseInfo.ContentType) + Environment.NewLine);
            json.Append(String.Format("\t{0}{1}{0} : {0}{2}{0}", quotes, "StatusCode", responseInfo.StatusCode) + Environment.NewLine);

            // Add headers
            json.Append(String.Format("\t{0}{1}{0} : ", quotes, "Headers") + "{" + Environment.NewLine);
            foreach (string header in responseInfo.Headers.Keys)
            {
                json.Append(String.Format("\t\t{0}{1}{0} : {0}{2}{0}", quotes, header, responseInfo.Headers[header].ToString()) + Environment.NewLine);
            }
            json.Append("\t}" + Environment.NewLine);
            json.Append("}" + Environment.NewLine);
            return(json.ToString());
        }
Exemple #2
0
        private static ResponseInfo GetResponseInfo(string requestId, DateTime responseTime, HttpResponseMessage response, DateTime requestTime)
        {
            var responseLogInfo = new ResponseInfo()
            {
                RequestID = requestId
            };

            TimeSpan elapsed = responseTime - requestTime;

            responseLogInfo.StatusCode  = (int)response.StatusCode;
            responseLogInfo.Timestamp   = responseTime;
            responseLogInfo.ElapsedTime = (int)elapsed.TotalMilliseconds;

            if (response.Content != null)
            {
                responseLogInfo.Body        = response.Content.ReadAsByteArrayAsync().Result;
                responseLogInfo.ContentType = response.Content.Headers.ContentType.MediaType;
                responseLogInfo.Headers     = GetHeaders(response.Content.Headers);
            }
            return(responseLogInfo);
        }
Exemple #3
0
 /// <summary>
 /// Logs response
 /// </summary>
 /// <param name="responseInfo"></param>
 protected virtual void Log(ResponseInfo responseInfo)
 {
 }
Exemple #4
0
 private string GetCSVLine(ResponseInfo responseInfo) => String.Format("{1}{0}{2}{0}{3}{0}{4}{0}{5}{0}{6}{0}{7}", _delimiter, responseInfo.RequestID, responseInfo.Timestamp.ToString(_defaultDateTimeFormat), responseInfo.StatusCode, responseInfo.ContentType, responseInfo.Body.Length, responseInfo.ElapsedTime.GetValueOrDefault(0), GetHeadersCSVLine(responseInfo.Headers, _maxHeaders));