public static void PublishNativeProxyStatistics(HttpContextBase httpContext)
        {
            RequestLogger logger = RequestLogger.GetLogger(httpContext);
            string        value  = httpContext.Response.Headers[NativeProxyLogHelper.NativeProxyStatusHeaders.BackEndHttpStatus];

            if (!string.IsNullOrEmpty(value))
            {
                logger.LogField(LogKey.BackendStatus, value);
            }
            string text = httpContext.Response.Headers[NativeProxyLogHelper.NativeProxyStatusHeaders.ProxyErrorHResult];
            string arg  = httpContext.Response.Headers[NativeProxyLogHelper.NativeProxyStatusHeaders.ProxyErrorLabel];
            string arg2 = httpContext.Response.Headers[NativeProxyLogHelper.NativeProxyStatusHeaders.ProxyErrorMessage];

            if (!string.IsNullOrEmpty(text))
            {
                logger.LogField(LogKey.ErrorCode, text);
                string value2 = string.Format("[{0}] [{1}] {2}", text, arg, arg2);
                logger.AppendErrorInfo("ProxyError", value2);
            }
            HttpWorkerRequest httpWorkerRequest = (HttpWorkerRequest)((IServiceProvider)httpContext).GetService(typeof(HttpWorkerRequest));
            bool hasWinHttpQuery = NativeProxyLogHelper.PublishTimestamps(httpWorkerRequest, logger);

            NativeProxyLogHelper.PublishLatencies(httpWorkerRequest, logger, hasWinHttpQuery);
            NativeProxyLogHelper.PublishCounters(httpWorkerRequest, logger);
            NativeProxyLogHelper.PublishStreamStats(httpWorkerRequest, logger);
            NativeProxyLogHelper.PublishGenericStats(httpWorkerRequest, logger, NativeProxyLogHelper.NativeProxyStatisticsVariables.RequestBufferSizeFootprints);
            NativeProxyLogHelper.PublishGenericStats(httpWorkerRequest, logger, NativeProxyLogHelper.NativeProxyStatisticsVariables.ResponseBufferSizeFootprints);
            if (NativeProxyLogHelper.LogBufferCopyStats.Value)
            {
                NativeProxyLogHelper.PublishGenericStats(httpWorkerRequest, logger, NativeProxyLogHelper.NativeProxyStatisticsVariables.BufferCopyStatsClientUpload);
                NativeProxyLogHelper.PublishGenericStats(httpWorkerRequest, logger, NativeProxyLogHelper.NativeProxyStatisticsVariables.BufferCopyStatsServerQuery);
                NativeProxyLogHelper.PublishGenericStats(httpWorkerRequest, logger, NativeProxyLogHelper.NativeProxyStatisticsVariables.BufferCopyStatsServerDownload);
            }
        }
        private static void PublishStreamStats(HttpWorkerRequest httpWorkerRequest, RequestLogger logger)
        {
            string serverVariable = httpWorkerRequest.GetServerVariable(NativeProxyLogHelper.NativeProxyStatisticsVariables.StreamStats);

            if (!string.IsNullOrEmpty(serverVariable))
            {
                logger.AppendGenericInfo(NativeProxyLogHelper.NativeProxyStatisticsVariables.StreamStats, serverVariable);
                long[] array = NativeProxyLogHelper.ConvertStatisticsDataArray(serverVariable);
                logger.LogField(LogKey.RequestBytes, array[0]);
                logger.LogField(LogKey.ResponseBytes, array[2]);
            }
        }
        private static void PublishLatencies(HttpWorkerRequest httpWorkerRequest, RequestLogger logger, bool hasWinHttpQuery)
        {
            string serverVariable = httpWorkerRequest.GetServerVariable(NativeProxyLogHelper.NativeProxyStatisticsVariables.Latencies);

            if (!string.IsNullOrEmpty(serverVariable))
            {
                logger.AppendGenericInfo(NativeProxyLogHelper.NativeProxyStatisticsVariables.Latencies, serverVariable);
                long[] array = NativeProxyLogHelper.ConvertStatisticsDataArray(serverVariable);
                logger.LogField(LogKey.ClientReqStreamLatency, array[0]);
                logger.LogField(LogKey.ClientRespStreamLatency, array[1]);
                logger.LogField(LogKey.BackendReqStreamLatency, array[2]);
                if (hasWinHttpQuery)
                {
                    logger.LogField(LogKey.BackendRespStreamLatency, array[3]);
                    return;
                }
                logger.LogField(LogKey.BackendRespStreamLatency, array[4]);
            }
        }
示例#4
0
        private void AddDiagnosticInfo(HttpContextBase context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            this.Logger.LogField(LogKey.DateTime, DateTime.UtcNow.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffZ"));
            this.Logger.LogField(LogKey.RequestId, this.activityScope.ActivityId);
            this.Logger.LogField(LogKey.MajorVersion, Constants.VersionMajor);
            this.Logger.LogField(LogKey.MinorVersion, Constants.VersionMinor);
            this.Logger.LogField(LogKey.BuildVersion, Constants.VersionBuild);
            this.Logger.LogField(LogKey.RevisionVersion, Constants.VersionRevision);
            this.Logger.LogField(LogKey.Protocol, HttpProxyGlobals.ProtocolType);
            IIdentity identity = (context.User != null) ? context.User.Identity : null;

            if (identity != null)
            {
                this.Logger.LogField(LogKey.AuthenticationType, identity.AuthenticationType);
                this.Logger.LogField(LogKey.IsAuthenticated, identity.IsAuthenticated);
                this.Logger.LogField(LogKey.AuthenticatedUser, identity.Name);
            }
            this.Logger.LogField(LogKey.UserAgent, context.Request.UserAgent);
            this.Logger.LogField(LogKey.ClientIpAddress, context.Request.UserHostAddress);
            this.Logger.LogField(LogKey.ClientRequestId, context.Request.Headers[WellKnownHeader.XRequestId]);
            this.Logger.LogField(LogKey.UrlHost, context.Request.Url.DnsSafeHost);
            this.Logger.LogField(LogKey.UrlStem, context.Request.Url.LocalPath);
            this.Logger.LogField(LogKey.UrlQuery, context.Request.Url.Query);
            this.Logger.LogField(LogKey.Method, context.Request.HttpMethod);
            this.Logger.LogField(LogKey.ProtocolAction, context.Request.QueryString["Action"]);
            this.Logger.LogField(LogKey.ServerHostName, Constants.MachineName);
            this.Logger.LogField(LogKey.HttpStatus, context.Response.StatusCode);
            this.Logger.LogField(LogKey.BackEndGenericInfo, context.Response.Headers[WellKnownHeader.XBackendHeaderPrefix]);
            string value = context.Items["AnonymousRequestFilterModule"] as string;

            if (!string.IsNullOrEmpty(value))
            {
                this.Logger.AppendGenericInfo("AnonymousRequestFilterModule", value);
            }
            NativeProxyLogHelper.PublishNativeProxyStatistics(context);
            this.Logger.LatencyTracker.LogElapsedTimeInMilliseconds(LogKey.TotalRequestTime);
        }
        private static bool PublishTimestamps(HttpWorkerRequest httpWorkerRequest, RequestLogger logger)
        {
            bool   result         = false;
            string serverVariable = httpWorkerRequest.GetServerVariable(NativeProxyLogHelper.NativeProxyStatisticsVariables.Timestamps);

            if (!string.IsNullOrEmpty(serverVariable))
            {
                logger.AppendGenericInfo(NativeProxyLogHelper.NativeProxyStatisticsVariables.Timestamps, serverVariable);
                long[] array = NativeProxyLogHelper.ConvertStatisticsDataArray(serverVariable);
                logger.LogField(LogKey.ModuleToHandlerSwitchingLatency, array[1] - array[0]);
                long num = array[14] - array[3];
                logger.LogField(LogKey.BackendProcessingLatency, num);
                long num2 = num;
                if (array[22] >= 0L)
                {
                    num2 = array[22] - array[3];
                }
                logger.LogField(LogKey.ProxyTime, num2);
                result = (array[15] >= 0L);
            }
            return(result);
        }