Example #1
0
        public void LogCannotMoveSequences(
            ISilverbackLogger logger,
            IRawInboundEnvelope envelope,
            ISequence sequence)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.CannotMoveSequences))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _cannotMoveSequences.Invoke(
                logger.InnerLogger,
                sequence.GetType().Name,
                envelope.ActualEndpointDisplayName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                null);
        }
Example #2
0
        public void LogProduced(
            ISilverbackLogger logger,
            IProducerEndpoint endpoint,
            string actualEndpoint,
            IReadOnlyCollection <MessageHeader>?headers,
            IBrokerMessageIdentifier?brokerMessageIdentifier)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.MessageProduced))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                endpoint,
                headers,
                brokerMessageIdentifier);

            _messageProduced.Invoke(
                logger.InnerLogger,
                actualEndpoint,
                headers?.GetValue(DefaultMessageHeaders.MessageType),
                headers?.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                null);
        }
Example #3
0
        public void LogProduceError(
            ISilverbackLogger logger,
            IProducerEndpoint endpoint,
            string actualEndpoint,
            IReadOnlyCollection <MessageHeader>?headers,
            Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.MessageProduced))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                endpoint,
                headers,
                null);

            _errorProducingMessage.Invoke(
                logger.InnerLogger,
                actualEndpoint,
                headers?.GetValue(DefaultMessageHeaders.MessageType),
                headers?.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                exception);
        }
Example #4
0
        public void LogInboundTrace(
            ISilverbackLogger logger,
            LogLevel logLevel,
            EventId eventId,
            string message,
            IRawInboundEnvelope envelope,
            Exception?exception,
            Func <object?[]>?argumentsProvider = null)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.LowLevelTracing))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            var args = new List <object?>(argumentsProvider?.Invoke() ?? Array.Empty <object?>());

            args.Add(envelope.ActualEndpointDisplayName);
            args.Add(envelope.Headers.GetValue(DefaultMessageHeaders.MessageType));
            args.Add(envelope.Headers.GetValue(DefaultMessageHeaders.MessageId));
            args.Add(value1);
            args.Add(value2);

            logger.InnerLogger.Log(
                logLevel,
                eventId,
                exception,
                EnrichMessage(message),
                args.ToArray());
        }
Example #5
0
        public void LogMoved(
            ISilverbackLogger logger,
            IRawInboundEnvelope envelope,
            IProducerEndpoint targetEndpoint)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.MessageMoved))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _messageMoved.Invoke(
                logger.InnerLogger,
                targetEndpoint.DisplayName,
                envelope.ActualEndpointDisplayName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                null);
        }
Example #6
0
        public static async Task ExecuteAndTraceConsumerActionAsync(
            this ISilverbackLogger logger,
            IConsumer?consumer,
            Func <Task> action,
            string enterMessage,
            string successMessage,
            string errorMessage,
            Func <object?[]>?argumentsProvider = null)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.LowLevelTracing))
            {
                await action.Invoke().ConfigureAwait(false);

                return;
            }

            var args = new List <object?>(argumentsProvider?.Invoke() ?? Array.Empty <object>());

            args.Add(consumer?.Id ?? string.Empty);
            args.Add(consumer?.Endpoint.DisplayName ?? string.Empty);

            logger.InnerLogger.Log(
                IntegrationLogEvents.LowLevelTracing.Level,
                IntegrationLogEvents.LowLevelTracing.EventId,
                enterMessage + GetConsumerMessageDataString(),
                args.ToArray());

            try
            {
                await action.Invoke().ConfigureAwait(false);

                logger.InnerLogger.Log(
                    IntegrationLogEvents.LowLevelTracing.Level,
                    IntegrationLogEvents.LowLevelTracing.EventId,
                    successMessage + GetConsumerMessageDataString(),
                    args.ToArray());
            }
            catch (Exception ex)
            {
                logger.InnerLogger.Log(
                    IntegrationLogEvents.LowLevelTracing.Level,
                    IntegrationLogEvents.LowLevelTracing.EventId,
                    ex,
                    errorMessage + GetConsumerMessageDataString(),
                    args.ToArray());

                throw;
            }
        }
Example #7
0
        public static void LogSequenceStarted(
            this ISilverbackLogger logger,
            ISequence sequence)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.SequenceStarted))
            {
                return;
            }

            SequenceStarted(
                logger.InnerLogger,
                sequence.GetType().Name,
                sequence.SequenceId,
                null);
        }
Example #8
0
        public static void LogLowLevelTrace(
            this ISilverbackLogger logger,
            string message,
            Func <object[]> argumentsProvider)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.LowLevelTracing))
            {
                return;
            }

            logger.InnerLogger.Log(
                IntegrationLogEvents.LowLevelTracing.Level,
                IntegrationLogEvents.LowLevelTracing.EventId,
                message,
                argumentsProvider.Invoke());
        }
Example #9
0
        public static void LogSequenceAbortingError(
            this ISilverbackLogger logger,
            ISequence sequence,
            Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.ErrorAbortingInboundSequence))
            {
                return;
            }

            ErrorAbortingInboundSequence(
                logger.InnerLogger,
                sequence.GetType().Name,
                sequence.SequenceId,
                exception);
        }
Example #10
0
        public static void LogIncompleteSequenceAborted(
            this ISilverbackLogger logger,
            ISequence sequence)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.IncompleteSequenceAborted))
            {
                return;
            }

            IncompleteSequenceAborted(
                logger.InnerLogger,
                sequence.GetType().Name,
                sequence.SequenceId,
                sequence.Length,
                null);
        }
Example #11
0
        public static void LogConfluentConsumerError(
            this ISilverbackLogger logger,
            Error error,
            KafkaConsumer consumer)
        {
            if (!logger.IsEnabled(KafkaLogEvents.ConfluentConsumerError))
            {
                return;
            }

            ConfluentConsumerError(
                logger.InnerLogger,
                GetErrorReason(error),
                (int)error.Code,
                consumer.Id,
                consumer.Endpoint.Name,
                null);
        }
Example #12
0
        public static void LogMqttClientError(
            this ISilverbackLogger logger,
            string?source,
            string message,
            object[]?parameters,
            Exception?exception)
        {
            if (!logger.IsEnabled(MqttLogEvents.MqttClientLogError))
            {
                return;
            }

            MqttClientLogError(
                logger.InnerLogger,
                source ?? "-",
                FormatMqttClientMessage(message, parameters),
                exception);
        }
Example #13
0
        public static void LogConsumerRollbackError(
            this ISilverbackLogger logger,
            IConsumer consumer,
            IReadOnlyCollection <IBrokerMessageIdentifier> identifiers,
            Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.ConsumerRollbackError))
            {
                return;
            }

            ConsumerRollbackError(
                logger.InnerLogger,
                consumer.Id,
                consumer.Endpoint.DisplayName,
                string.Join(", ", identifiers.Select(identifier => identifier.ToVerboseLogString())),
                exception);
        }
Example #14
0
        public static void LogSequenceAborted(
            this ISilverbackLogger logger,
            ISequence sequence,
            SequenceAbortReason reason)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.SequenceProcessingAborted))
            {
                return;
            }

            SequenceProcessingAborted(
                logger.InnerLogger,
                sequence.GetType().Name,
                sequence.SequenceId,
                sequence.Length,
                reason,
                null);
        }
Example #15
0
        public static void LogMessageAddedToSequence(
            this ISilverbackLogger logger,
            IRawInboundEnvelope envelope,
            ISequence sequence)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.MessageAddedToSequence))
            {
                return;
            }

            MessageAddedToSequence(
                logger.InnerLogger,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                sequence.GetType().Name,
                sequence.SequenceId,
                sequence.Length,
                null);
        }
Example #16
0
        public static void LogOffsetCommitError(
            this ISilverbackLogger logger,
            TopicPartitionOffsetError topicPartitionOffsetError,
            KafkaConsumer consumer)
        {
            if (!logger.IsEnabled(KafkaLogEvents.OffsetCommitError))
            {
                return;
            }

            OffsetCommitError(
                logger.InnerLogger,
                topicPartitionOffsetError.Topic,
                topicPartitionOffsetError.Partition,
                topicPartitionOffsetError.Offset,
                GetErrorReason(topicPartitionOffsetError.Error),
                (int)topicPartitionOffsetError.Error.Code,
                consumer.Id,
                null);
        }
Example #17
0
        public void LogProcessing(ISilverbackLogger logger, IRawInboundEnvelope envelope)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.ProcessingInboundMessage))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _processingInboundMessage.Invoke(
                logger.InnerLogger,
                envelope.ActualEndpointName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                null);
        }
Example #18
0
        public void LogProduceError(ISilverbackLogger logger, IOutboundEnvelope envelope, Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.MessageProduced))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                null);

            _errorProducingMessage.Invoke(
                logger.InnerLogger,
                envelope.ActualEndpointDisplayName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                exception);
        }
Example #19
0
        public void LogWrittenToOutbox(ISilverbackLogger logger, IOutboundEnvelope envelope)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.MessageWrittenToOutbox))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _messageWrittenToOutbox.Invoke(
                logger.InnerLogger,
                envelope.ActualEndpointDisplayName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                null);
        }
Example #20
0
        public static void LogConsumerLowLevelTrace(
            this ISilverbackLogger logger,
            IConsumer?consumer,
            string message,
            Func <object?[]>?argumentsProvider = null)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.LowLevelTracing))
            {
                return;
            }

            var args = new List <object?>(argumentsProvider?.Invoke() ?? Array.Empty <object>());

            args.Add(consumer?.Id ?? string.Empty);
            args.Add(consumer?.Endpoint.DisplayName ?? string.Empty);

            logger.InnerLogger.Log(
                IntegrationLogEvents.LowLevelTracing.Level,
                IntegrationLogEvents.LowLevelTracing.EventId,
                message + GetConsumerMessageDataString(),
                args.ToArray());
        }
Example #21
0
        public void LogErrorProducingOutboxStoredMessage(
            ISilverbackLogger logger,
            IOutboundEnvelope envelope,
            Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.ErrorProducingOutboxStoredMessage))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _errorProducingOutboxStoredMessage.Invoke(
                logger.InnerLogger,
                envelope.ActualEndpointName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                exception);
        }
Example #22
0
        public void LogProcessingFatalError(
            ISilverbackLogger logger,
            IRawInboundEnvelope envelope,
            Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.ConsumerFatalError))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _consumerFatalError.Invoke(
                logger.InnerLogger,
                envelope.ActualEndpointName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                exception);
        }
Example #23
0
        public void LogRollbackToSkipFailed(
            ISilverbackLogger logger,
            IRawInboundEnvelope envelope,
            Exception exception)
        {
            if (!logger.IsEnabled(IntegrationLogEvents.RollbackToSkipFailed))
            {
                return;
            }

            (string?value1, string?value2) = _logEnricher.GetAdditionalValues(
                envelope.Endpoint,
                envelope.Headers,
                envelope.BrokerMessageIdentifier);

            _rollbackToSkipFailed.Invoke(
                logger.InnerLogger,
                envelope.ActualEndpointDisplayName,
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageType),
                envelope.Headers.GetValue(DefaultMessageHeaders.MessageId),
                value1,
                value2,
                exception);
        }
Example #24
0
 public bool IsEnabled(LogLevel logLevel) => _logger.IsEnabled(logLevel);