Пример #1
0
        private void LogResponse(Logger logger, KissLog.Web.HttpResponse response, ResponseSniffer sniffer)
        {
            try
            {
                using (sniffer.MirrorStream)
                {
                    sniffer.MirrorStream.Position = 0;

                    if (InternalHelpers.PreFilterShouldLogResponseBody(logger, sniffer.MirrorStream, response.Properties))
                    {
                        using (TemporaryFile tempFile = new TemporaryFile())
                        {
                            using (var fs = File.OpenWrite(tempFile.FileName))
                            {
                                sniffer.MirrorStream.CopyTo(fs);
                            }

                            string responseFileName = InternalHelpers.ResponseFileName(response.Properties.Headers);
                            logger.LogFile(tempFile.FileName, responseFileName);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder();
                sb.AppendLine("Error logging HTTP Response Content as file");
                sb.AppendLine(ex.ToString());

                KissLog.Internal.InternalHelpers.Log(sb.ToString(), LogLevel.Error);
            }
        }
Пример #2
0
        private long ReadResponseLength(ResponseSniffer sniffer)
        {
            if (sniffer != null)
            {
                try
                {
                    return(sniffer.MirrorStream.Length);
                }
                catch (Exception ex)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Error logging HTTP Response length");
                    sb.AppendLine(ex.ToString());

                    KissLog.Internal.InternalHelpers.Log(sb.ToString(), LogLevel.Error);

                    return(0);
                }
            }

            return(0);
        }