コード例 #1
0
        public async Task <string> LogPayloadAsync(string correlationId, string payload, string extension = "txt")
        {
            var monitorMessage = new MonitorMessage()
            {
                CorrelationId  = correlationId,
                RequestBody    = payload,
                RequestAddress = "payload logger",
                MessageType    = MonitorMessageTypes.GenericObjectSender,
                RequestMethod  = "PAYLOADLOGGER"
            };

            await _monitorLogger.WriteMessage(monitorMessage);

            return("");
        }
コード例 #2
0
        /// <summary>
        /// SendAsync method implementation
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        protected override async Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken)
        {
            var httpContext = _httpContextAccessor.HttpContext;

            // set required headers
            AddHeaderValue(request, HttpHeaderConstants.ClientCorrelationIdHeaderName, $"{MonitorMessageHelper.GetCurrentCorrelationId(httpContext)}");
            AddHeaderValue(request, HttpConstants.ArchitectureMetadataName, $"{MonitorMessageHelper.GetCurrentArchitectureMetadata(httpContext)}");

            // log request
            var monitorMessage = await MonitorMessageHelper.CreateForHttpClient(httpContext, request);

            if (!String.IsNullOrWhiteSpace(monitorMessage.CorrelationId))
            {
                await _monitorLogger.WriteMessage(monitorMessage);
            }


            try
            {
                var response = await InnerSendAsync(request, cancellationToken);

                await MonitorMessageHelper.UpdateForHttpClient(monitorMessage, response);

                return(response);
            }
            catch (Exception ex)
            {
                await MonitorMessageHelper.UpdateForHttpClient(monitorMessage, null, ex);

                throw;
            }
            finally
            {
                // if this call is done from async process then flush monitor logger messages
                if (httpContext == null || String.IsNullOrWhiteSpace(httpContext.Request.Method))
                {
                    await _monitorLogger.Flush(false);
                }
            }
        }