src/Arcus.WebApi.Logging.Core/Correlation/HttpCorrelation.cs
/// <summary>
/// Correlate the current HTTP request according to the previously configured <see cref="CorrelationInfoOptions"/>;
/// returning an <paramref name="errorMessage"/> when the correlation failed.
/// </summary>
/// <param name="errorMessage">The failure message that describes why the correlation of the HTTP request wasn't successful.</param>
/// <returns>
///     <para>[true] when the HTTP request was successfully correlated and the HTTP response was altered accordingly;</para>
///     <para>[false] there was a problem with the correlation, describing the failure in the <paramref name="errorMessage"/>.</para>
/// </returns>
/// <exception cref="ArgumentNullException">Thrown when the given <see cref="HttpContext"/> is not available to correlate the request with the response.</exception>
/// <exception cref="ArgumentException">Thrown when the given <see cref="HttpContext"/> doesn't have any response headers to set the correlation headers.</exception>
Correlate the current HTTP request according to the previously configured ;
returning an  when the correlation failed.
Correlate the current HTTP request according to the previously configured ; returning an when the correlation failed .
public bool TryHttpCorrelate(out string errorMessage)
        {
            HttpContext httpContext = _httpContextAccessor.HttpContext;
            Guard.NotNull(httpContext, nameof(httpContext), "Requires a HTTP context from the HTTP context accessor to start correlating the HTTP request");
            Guard.For<ArgumentException>(() => httpContext.Response is null, "Requires a 'Response'");
            Guard.For<ArgumentException>(() => httpContext.Response.Headers is null, "Requires a 'Response' object with headers");
            if (httpContext.Request.Headers.TryGetValue(_options.Transaction.HeaderName, out StringValues transactionIds))
            {
                if (!_options.Transaction.AllowInRequest)
                {
                    _logger.LogError("No correlation request header '{HeaderName}' for transaction ID was allowed in request", _options.Transaction.HeaderName);
                    errorMessage = $"No correlation transaction ID request header '{_options.Transaction.HeaderName}' was allowed in the request";
                    return false;
                }
                _logger.LogTrace("Correlation request header '{HeaderName}' found with transaction ID '{TransactionId}'", _options.Transaction.HeaderName, transactionIds);
            }
            string operationId = DetermineOperationId(httpContext);
            string transactionId = DetermineTransactionId(transactionIds);
            var correlation = new CorrelationInfo(operationId, transactionId);
            httpContext.Features.Set(correlation);
            AddCorrelationResponseHeaders(httpContext);
            errorMessage = null;
            return true;
        }
public bool TryHttpCorrelate ( out string errorMessage ) { HttpContext httpContext = _httpContextAccessor . HttpContext ; Guard . NotNull ( httpContext , nameof ( httpContext ) , " " ) ; Guard . For < ArgumentException > ( ( ) => httpContext . Response is null , " " ) ; Guard . For < ArgumentException > ( ( ) => httpContext . Response . Headers is null , " " ) ; if ( httpContext . Request . Headers . TryGetValue ( _options . Transaction . HeaderName , out StringValues transactionIds ) ) { if ( ! _options . Transaction . AllowInRequest ) { _logger . LogError ( " " , _options . Transaction . HeaderName ) ; errorMessage = $" No correlation transaction ID request header ' { _options . Transaction . HeaderName } ' was allowed in the request " ; return false ; } _logger . LogTrace ( " " , _options . Transaction . HeaderName , transactionIds ) ; } string operationId = DetermineOperationId ( httpContext ) ; string transactionId = DetermineTransactionId ( transactionIds ) ; var correlation = new CorrelationInfo ( operationId , transactionId ) ; httpContext . Features . Set ( correlation ) ; AddCorrelationResponseHeaders ( httpContext ) ; errorMessage = null ; return true ; }
Correlate the current HTTP request according to the previously configured ;
returning an  when the correlation failed.
Correlate the current HTTP request according to the previously configured ; returning an when the correlation failed .
[true] when the HTTP request was successfully correlated and the HTTP response was altered accordingly;[false] there was a problem with the correlation, describing the failure in the .
[ true ] when the HTTP request was successfully correlated and the HTTP response was altered accordingly ; [ false ] there was a problem with the correlation describing the failure in the .
Thrown when the given  is not available to correlate the request with the response.
Thrown when the given is not available to correlate the request with the response .
Thrown when the given  doesn't have any response headers to set the correlation headers.
Thrown when the given doesn ' t have any response headers to set the correlation headers .
string
out
errorMessage
The failure message that describes why the correlation of the HTTP request wasn't successful.
The failure message that describes why the correlation of the HTTP request wasn ' t successful .