Skip to content

Commit

Permalink
Added more information to logged events
Browse files Browse the repository at this point in the history
  • Loading branch information
Kralizek committed Oct 12, 2015
1 parent fe32a48 commit e88dd4b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Core/Configuration/NybusBusBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void SubscribeToEvent<TEvent>(Func<EventContext<TEvent>, Task> handler)
where TEventHandler : IEventHandler<TEvent>
where TEvent : class, IEvent
{
_logger.LogVerbose(new { eventType = typeof(TEvent).FullName, handlerType = typeof(TEventHandler).FullName, correlationId = message.CorrelationId }, arg => $"Handling event of type {arg.eventType} with correlationId {arg.correlationId} with handler of type {arg.handlerType}");
_logger.LogVerbose(new { eventType = typeof(TEvent).FullName, handlerType = handler.GetType().FullName, correlationId = message.CorrelationId, @event = message.Event.ToString() }, arg => $"Handling event of type {arg.eventType} with correlationId {arg.correlationId} with handler of type {arg.handlerType}. Event: {arg.@event}");

var context = _options.EventContextFactory.CreateContext(message, _options);
await handler.Handle(context).ConfigureAwait(false);
Expand Down Expand Up @@ -135,7 +135,7 @@ public void SubscribeToCommand<TCommand>(Func<CommandContext<TCommand>, Task> ha
private async Task HandleCommandMessage<TCommandHandler, TCommand>(TCommandHandler handler, CommandMessage<TCommand> message)
where TCommandHandler : ICommandHandler<TCommand> where TCommand : class, ICommand
{
_logger.LogVerbose(new { commandType = typeof(TCommand).FullName, handlerType = typeof(TCommandHandler).FullName, correlationId = message.CorrelationId }, arg => $"Handling command of type {arg.commandType} with correlationId {arg.correlationId} with handler of type {arg.handlerType}");
_logger.LogVerbose(new { commandType = typeof(TCommand).FullName, handlerType = handler.GetType().FullName, correlationId = message.CorrelationId, command = message.Command.ToString() }, arg => $"Handling command of type {arg.commandType} with correlationId {arg.correlationId} with handler of type {arg.handlerType}. Command: {arg.command}");

var context = _options.CommandContextFactory.CreateContext(message, _options);
await handler.Handle(context).ConfigureAwait(false);
Expand Down
16 changes: 8 additions & 8 deletions src/MassTransit/MassTransit/MassTransitBusEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,17 @@ private async Task HandleCommand<TCommand>(CommandReceived<TCommand> commandHand
{
CommandMessage<TCommand> message = _options.ContextManager.CreateCommandMessage(context);

_logger.LogVerbose(new { commandType = typeof(TCommand).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount, command = message.Command },
arg => $"Received command of type {arg.commandType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Command: {arg.command.ToString()}");
_logger.LogVerbose(new { commandType = typeof(TCommand).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount, command = message.Command.ToString() },
arg => $"Received command of type {arg.commandType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Command: {arg.command}");

try
{
await commandHandler.Invoke(message).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(new { commandType = typeof(TCommand).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount, command = context.Message }, ex,
(arg, e) => $"Error while processing event of type {arg.commandType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Command: {arg.command.ToString()}. Error: {e.Message}");
_logger.LogError(new { commandType = typeof(TCommand).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount, command = context.Message.ToString() }, ex,
(arg, e) => $"Error while processing event of type {arg.commandType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Command: {arg.command}. Error: {e.Message}");

var handled = await _options.CommandErrorStrategy.HandleError(context, ex).ConfigureAwait(false);

Expand Down Expand Up @@ -115,17 +115,17 @@ private async Task HandleCommand<TCommand>(CommandReceived<TCommand> commandHand
{
EventMessage<TEvent> message = _options.ContextManager.CreateEventMessage(context);

_logger.LogVerbose(new { @event = message.Event, eventType = typeof(TEvent).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount },
arg => $"Received event of type {arg.eventType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Event: {arg.@event.ToString()}");
_logger.LogVerbose(new { @event = message.Event.ToString(), eventType = typeof(TEvent).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount },
arg => $"Received event of type {arg.eventType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Event: {arg.@event}");

try
{
await eventHandler.Invoke(message).ConfigureAwait(false);
}
catch (Exception ex)
{
_logger.LogError(new { eventType = typeof(TEvent).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount, @event = context.Message }, ex,
(arg, e) =>$"Error while processing event of type {arg.eventType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Event: {arg.@event.ToString()}. Error: {e.Message}");
_logger.LogError(new { eventType = typeof(TEvent).FullName, correlationId = message.CorrelationId, retryCount = context.RetryCount, @event = context.Message.ToString() }, ex,
(arg, e) =>$"Error while processing event of type {arg.eventType} with correlationId {arg.correlationId}. (Try n. {arg.retryCount}). Event: {arg.@event}. Error: {e.Message}");

var handled = await _options.EventErrorStrategy.HandleError(context, ex).ConfigureAwait(false);

Expand Down

0 comments on commit e88dd4b

Please sign in to comment.