Ejemplo n.º 1
0
        public Task ConsumeFault <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType, Exception exception) where T : class
        {
            var messageTypeName = context.Message.GetType().FullName;

            MessageContext.IsFaulted.Value = true;

            Logger
            .Error(exception, MessageTemplate, ShortMessageName.Get(messageTypeName), "failed", duration.TotalMilliseconds.Round());

            return(Task.CompletedTask);
        }
Ejemplo n.º 2
0
        public Task PostConsume <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType) where T : class
        {
            var messageTypeName = context.Message.GetType().FullName;

            if (MessageContext.IsFaulted?.Value == true && MessageContext.RetryContext.Value != null)
            {
                MessageContext.RetryContext.Value.LogRetry();

                return(Task.CompletedTask);
            }

            Logger
            .ForContext(GetEnrichers(context, duration))
            .Information(MessageTemplate, ShortMessageName.Get(messageTypeName), "processed", duration.TotalMilliseconds.Round());

            return(Task.CompletedTask);
        }
Ejemplo n.º 3
0
        public Task PreConsume <T>(ConsumeContext <T> context) where T : class
        {
            var messageTypeName = context.Message.GetType().FullName;

            MessageContext.MessageName.Value = new MessageName(messageTypeName);

            var sentTime = context.GetSentTime();

            LogContext.Push(new ILogEventEnricher[]
            {
                new FullMessageNameEnricher(messageTypeName),
                new QueueLogTypeEnricher(),
                new MessageBodyEnricher(context.Message),
                new MessageIdEnricher(context.MessageId),
            });

            if (!sentTime.HasValue)
            {
                Logger.Information("Received message {MessageName} message without SentTime", ShortMessageName.Get(messageTypeName));

                return(Task.CompletedTask);
            }

            var elapsed = (DateTime.UtcNow - sentTime.Value).TotalMilliseconds.Round();

            LogContext.Push(new ILogEventEnricher[]
            {
                new SentTimeEnricher(sentTime.Value),
                new LatencyEnricher(elapsed),
                new CreatedTimeEnricher(context.Headers.GetCreatedTime()),
            });

            Logger.Information("Message {MessageName} received after {Elapsed} ms", ShortMessageName.Get(messageTypeName), elapsed);

            return(Task.CompletedTask);
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var fullNameProperty = new LogEventProperty("FullMessageName", new ScalarValue(_fullname));

            logEvent.AddPropertyIfAbsent(fullNameProperty);

            var shortNameProperty = new LogEventProperty("MessageName", new ScalarValue(ShortMessageName.Get(_fullname)));

            logEvent.AddPropertyIfAbsent(shortNameProperty);
        }