Browse Source

Add LogContext for behaviour transacction

pull/952/head
Miguel Veloso 6 years ago
parent
commit
e6d1318418
1 changed files with 9 additions and 5 deletions
  1. +9
    -5
      src/Services/Ordering/Ordering.API/Application/Behaviors/TransactionBehaviour.cs

+ 9
- 5
src/Services/Ordering/Ordering.API/Application/Behaviors/TransactionBehaviour.cs View File

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.IntegrationEvents;
using Serilog.Context;
using System;
using System.Threading;
using System.Threading.Tasks;
@ -35,15 +36,18 @@ namespace Ordering.API.Application.Behaviors
await strategy.ExecuteAsync(async () =>
{
_logger.LogInformation("----- Begin transaction for {CommandName} ({@Command})", typeName, request);
var transaction = await _dbContext.BeginTransactionAsync();
await _dbContext.BeginTransactionAsync();
using (LogContext.PushProperty("TransactionContext", transaction.TransactionId))
{
_logger.LogInformation("----- Begin transaction {TransactionId} for {CommandName} ({@Command})", transaction.TransactionId, typeName, request);
response = await next();
response = await next();
await _dbContext.CommitTransactionAsync();
await _dbContext.CommitTransactionAsync();
_logger.LogInformation("----- Transaction commited for {CommandName}", typeName);
_logger.LogInformation("----- Transaction {TransactionId} committed for {CommandName}", transaction.TransactionId, typeName);
}
await _orderingIntegrationEventService.PublishEventsThroughEventBusAsync();
});


Loading…
Cancel
Save