Пример #1
0
        private void LogRequestLoggingInfo(HttpRequestMessage request)
        {
            var info = new ApiLoggingInfo();

            info.HttpMethod  = request.Method.Method;
            info.UriAccessed = request.RequestUri.AbsoluteUri;
            info.IpAddress   = HttpContext.Current != null ? HttpContext.Current.Request.UserHostAddress : "0.0.0.0";
            info.StartTime   = DateTime.Now;
            ExtractMessageHeadersIntoLoggingInfo(info, request.Headers.ToList());
            request.Properties.Add(_loggingInfoKey, info);
        }
Пример #2
0
 private void ExtractMessageHeadersIntoLoggingInfo(ApiLoggingInfo info, List <KeyValuePair <string, IEnumerable <string> > > headers)
 {
     headers.ForEach(h =>
     {
         var headerValues = new StringBuilder();
         if (h.Value != null)
         {
             foreach (var hv in h.Value)
             {
                 if (headerValues.Length > 0)
                 {
                     headerValues.Append(",");
                 }
                 headerValues.Append(hv);
             }
         }
         info.Headers.Add($"{h.Key}:{headerValues.ToString()}");
     });
 }