Пример #1
0
        private string CreateBaseFileName(HttpRequestMessage request, DateTimeOffset now)
        {
            var callName      = analyzer.GetCallName(request);
            var correlationId =
                request.Headers.GetCorrelationId() ??
                request.Properties.GetCorrelationId() ??
                now.ToString("yyyyMMddHHmmssfff");

            return($"{callName}_{correlationId}");
        }
Пример #2
0
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var correlationId = GetOrCreateCorrelationId(request, out bool existsInHeaders);

            if (!existsInHeaders)
            {
                request.Headers.Add(Extensions.CorrelationIdHeaderName, correlationId);
            }

            var callName = analyzer.GetCallName(request);

            using (LogContext.PushProperty("CorrelationId", correlationId))
                using (LogContext.PushProperty("CallName", callName))
                    using (OperationTimer(callName))
                    {
                        try
                        {
                            var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

                            MarkHttpStatus(callName, response.StatusCode);
                            if (analyzer.IsResponseSuccessful(response))
                            {
                                MarkSuccess(callName);
                                await LogAsync(LogEventLevel.Debug, callName, request, response).ConfigureAwait(false);
                            }
                            else
                            {
                                MarkError(callName);
                                await LogAsync(LogEventLevel.Warning, callName, request, response).ConfigureAwait(false);
                            }

                            return(response);
                        }
                        catch (Exception ex)
                        {
                            MarkError(callName);
                            await LogErrorAsync(callName, request, ex).ConfigureAwait(false);

                            throw;
                        }
                    }
        }