Add LogContext for behaviour transacction
This commit is contained in:
parent
ad7b33234f
commit
e6d1318418
@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
using Microsoft.eShopOnContainers.Services.Ordering.Infrastructure;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ordering.API.Application.IntegrationEvents;
|
using Ordering.API.Application.IntegrationEvents;
|
||||||
|
using Serilog.Context;
|
||||||
using System;
|
using System;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
@ -35,15 +36,18 @@ namespace Ordering.API.Application.Behaviors
|
|||||||
|
|
||||||
await strategy.ExecuteAsync(async () =>
|
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();
|
await _orderingIntegrationEventService.PublishEventsThroughEventBusAsync();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user