Beispiel #1
0
        public void SetTransactionIdPropertyName_WithBlankValue_Fails(string transactionIdPropertyName)
        {
            // Arrange
            var options = new CorrelationInfoEnricherOptions();

            // Act / Assert
            Assert.ThrowsAny <ArgumentException>(() => options.TransactionIdPropertyName = transactionIdPropertyName);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CorrelationInfoEnricher{TCorrelationInfo}"/> class.
        /// </summary>
        /// <param name="correlationInfoAccessor">The accessor implementation for the custom <see cref="CorrelationInfo"/> model.</param>
        /// <param name="options">The user-configurable options to change the behavior of the enricher.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="correlationInfoAccessor"/> is <c>null</c>.</exception>
        public CorrelationInfoEnricher(
            ICorrelationInfoAccessor <TCorrelationInfo> correlationInfoAccessor,
            CorrelationInfoEnricherOptions options)
        {
            Guard.NotNull(correlationInfoAccessor, nameof(correlationInfoAccessor), "Requires an correlation accessor to enrich the log events with correlation information");

            Options = options ?? new CorrelationInfoEnricherOptions();
            CorrelationInfoAccessor = correlationInfoAccessor;
        }
Beispiel #3
0
        public void SetOperationParentIdPropertyName_WithValue_GetsValue()
        {
            // Arrange
            var options  = new CorrelationInfoEnricherOptions();
            var expected = $"operation-parent-{Guid.NewGuid()}";

            // Act
            options.OperationParentIdPropertyName = expected;

            // Assert
            Assert.Equal(expected, options.OperationParentIdPropertyName);
        }
        /// <summary>
        /// Adds the <see cref="CorrelationInfoEnricher{TCorrelationInfo}"/> to the logger enrichment configuration which adds the custom <typeparamref name="TCorrelationInfo"/> information from the current context.
        /// </summary>
        /// <typeparam name="TCorrelationInfo">The type of the custom <see cref="CorrelationInfo"/> model.</typeparam>
        /// <param name="enrichmentConfiguration">The configuration to add the enricher.</param>
        /// <param name="correlationInfoAccessor">The accessor implementation for the <typeparamref name="TCorrelationInfo"/> model.</param>
        /// <param name="configureOptions">The function to configure the options to change the behavior of the enricher.</param>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="enrichmentConfiguration"/> or <paramref name="correlationInfoAccessor"/> is <c>null</c>.</exception>
        public static LoggerConfiguration WithCorrelationInfo <TCorrelationInfo>(
            this LoggerEnrichmentConfiguration enrichmentConfiguration,
            ICorrelationInfoAccessor <TCorrelationInfo> correlationInfoAccessor,
            Action <CorrelationInfoEnricherOptions> configureOptions)
            where TCorrelationInfo : CorrelationInfo
        {
            Guard.NotNull(enrichmentConfiguration, nameof(enrichmentConfiguration), "Requires an enrichment configuration to add the correlation information enricher");
            Guard.NotNull(correlationInfoAccessor, nameof(correlationInfoAccessor), "Requires an correlation accessor to retrieve the correlation information during the enrichment of the log events");

            var options = new CorrelationInfoEnricherOptions();

            configureOptions?.Invoke(options);

            return(enrichmentConfiguration.With(new CorrelationInfoEnricher <TCorrelationInfo>(correlationInfoAccessor, options)));
        }