Avoid logging exception details twice in a given log, clean up

This commit is contained in:
Reuben Bond 2023-05-05 07:06:28 -07:00
parent 57d9baf106
commit bcb1374d1e
51 changed files with 105 additions and 114 deletions

View File

@ -28,7 +28,7 @@ public class GrpcExceptionInterceptor : Interceptor
} }
catch (RpcException e) catch (RpcException e)
{ {
_logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); _logger.LogError(e, "Error calling via gRPC: {Status}", e.Status);
return default; return default;
} }
} }

View File

@ -28,7 +28,7 @@ public class GrpcExceptionInterceptor : Interceptor
} }
catch (RpcException e) catch (RpcException e)
{ {
_logger.LogError("Error calling via grpc: {Status} - {Message}", e.Status, e.Message); _logger.LogError(e, "Error calling via gRPC: {Status}", e.Status);
return default; return default;
} }
} }

View File

@ -59,7 +59,7 @@ public class DefaultRabbitMQPersistentConnection
.Or<BrokerUnreachableException>() .Or<BrokerUnreachableException>()
.WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) => .WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
{ {
_logger.LogWarning(ex, "RabbitMQ Client could not connect after {TimeOut}s ({ExceptionMessage})", $"{time.TotalSeconds:n1}", ex.Message); _logger.LogWarning(ex, "RabbitMQ Client could not connect after {TimeOut}s", $"{time.TotalSeconds:n1}");
} }
); );
@ -81,7 +81,7 @@ public class DefaultRabbitMQPersistentConnection
} }
else else
{ {
_logger.LogCritical("FATAL ERROR: RabbitMQ connections could not be created and opened"); _logger.LogCritical("Fatal error: RabbitMQ connections could not be created and opened");
return false; return false;
} }

View File

@ -57,7 +57,7 @@ public class EventBusRabbitMQ : IEventBus, IDisposable
.Or<SocketException>() .Or<SocketException>()
.WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) => .WaitAndRetry(_retryCount, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, time) =>
{ {
_logger.LogWarning(ex, "Could not publish event: {EventId} after {Timeout}s ({ExceptionMessage})", @event.Id, $"{time.TotalSeconds:n1}", ex.Message); _logger.LogWarning(ex, "Could not publish event: {EventId} after {Timeout}s", @event.Id, $"{time.TotalSeconds:n1}");
}); });
var eventName = @event.GetType().Name; var eventName = @event.GetType().Name;
@ -193,7 +193,7 @@ public class EventBusRabbitMQ : IEventBus, IDisposable
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogWarning(ex, "----- ERROR Processing message \"{Message}\"", message); _logger.LogWarning(ex, "Error Processing message \"{Message}\"", message);
} }
// Even on exception we take the message off the queue. // Even on exception we take the message off the queue.

View File

@ -140,7 +140,7 @@ public class EventBusServiceBus : IEventBus, IAsyncDisposable
var ex = args.Exception; var ex = args.Exception;
var context = args.ErrorSource; var context = args.ErrorSource;
_logger.LogError(ex, "ERROR handling message: {ExceptionMessage} - Context: {@ExceptionContext}", ex.Message, context); _logger.LogError(ex, "Error handling message - Context: {@ExceptionContext}", context);
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

@ -43,7 +43,7 @@ namespace Microsoft.AspNetCore.Hosting
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
onRetry: (exception, timeSpan, retry, ctx) => onRetry: (exception, timeSpan, retry, ctx) =>
{ {
logger.LogWarning(exception, "[{prefix}] Exception {ExceptionType} with message {Message} detected on attempt {retry} of {retries}", nameof(TContext), exception.GetType().Name, exception.Message, retry, retries); logger.LogWarning(exception, "[{prefix}] Error migrating database (attempt {retry} of {retries})", nameof(TContext), retry, retries);
}); });
//if the sql server container is not created on run docker compose this //if the sql server container is not created on run docker compose this

View File

@ -71,7 +71,7 @@ public class BasketController : ControllerBase
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId}", eventMessage.Id); _logger.LogError(ex, "Error Publishing integration event: {IntegrationEventId}", eventMessage.Id);
throw; throw;
} }

View File

@ -17,7 +17,7 @@ public class OrderStartedIntegrationEventHandler : IIntegrationEventHandler<Orde
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _repository.DeleteBasketAsync(@event.UserId.ToString()); await _repository.DeleteBasketAsync(@event.UserId.ToString());
} }

View File

@ -17,7 +17,7 @@ public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandl
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var userIds = _repository.GetUsers(); var userIds = _repository.GetUsers();
@ -36,7 +36,7 @@ public class ProductPriceChangedIntegrationEventHandler : IIntegrationEventHandl
if (itemsToUpdate != null) if (itemsToUpdate != null)
{ {
_logger.LogInformation("----- ProductPriceChangedIntegrationEventHandler - Updating items in basket for user: {BuyerId} ({@Items})", basket.BuyerId, itemsToUpdate); _logger.LogInformation("ProductPriceChangedIntegrationEventHandler - Updating items in basket for user: {BuyerId} ({@Items})", basket.BuyerId, itemsToUpdate);
foreach (var item in itemsToUpdate) foreach (var item in itemsToUpdate)
{ {

View File

@ -79,7 +79,7 @@ public class CartControllerTest
//Arrange //Arrange
var fakeCatalogItem = GetFakeCatalogItem(); var fakeCatalogItem = GetFakeCatalogItem();
_basketServiceMock.Setup(x => x.AddItemToBasket(It.IsAny<ApplicationUser>(), It.IsAny<Int32>())) _basketServiceMock.Setup(x => x.AddItemToBasket(It.IsAny<ApplicationUser>(), It.IsAny<int>()))
.Returns(Task.FromResult(1)); .Returns(Task.FromResult(1));
//Act //Act

View File

@ -60,14 +60,14 @@ public class CatalogContextSeed
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); logger.LogError(ex, "Error reading CSV headers");
return GetPreconfiguredCatalogBrands(); return GetPreconfiguredCatalogBrands();
} }
return File.ReadAllLines(csvFileCatalogBrands) return File.ReadAllLines(csvFileCatalogBrands)
.Skip(1) // skip header row .Skip(1) // skip header row
.SelectTry(x => CreateCatalogBrand(x)) .SelectTry(CreateCatalogBrand)
.OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; }) .OnCaughtException(ex => { logger.LogError(ex, "Error creating brand while seeding database"); return null; })
.Where(x => x != null); .Where(x => x != null);
} }
@ -75,9 +75,9 @@ public class CatalogContextSeed
{ {
brand = brand.Trim('"').Trim(); brand = brand.Trim('"').Trim();
if (String.IsNullOrEmpty(brand)) if (string.IsNullOrEmpty(brand))
{ {
throw new Exception("catalog Brand Name is empty"); throw new Exception("Catalog Brand Name is empty");
} }
return new CatalogBrand return new CatalogBrand
@ -115,14 +115,14 @@ public class CatalogContextSeed
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); logger.LogError(ex, "Error reading CSV headers");
return GetPreconfiguredCatalogTypes(); return GetPreconfiguredCatalogTypes();
} }
return File.ReadAllLines(csvFileCatalogTypes) return File.ReadAllLines(csvFileCatalogTypes)
.Skip(1) // skip header row .Skip(1) // skip header row
.SelectTry(x => CreateCatalogType(x)) .SelectTry(x => CreateCatalogType(x))
.OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; }) .OnCaughtException(ex => { logger.LogError(ex, "Error creating catalog type while seeding database"); return null; })
.Where(x => x != null); .Where(x => x != null);
} }
@ -130,7 +130,7 @@ public class CatalogContextSeed
{ {
type = type.Trim('"').Trim(); type = type.Trim('"').Trim();
if (String.IsNullOrEmpty(type)) if (string.IsNullOrEmpty(type))
{ {
throw new Exception("catalog Type Name is empty"); throw new Exception("catalog Type Name is empty");
} }
@ -170,7 +170,7 @@ public class CatalogContextSeed
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); logger.LogError(ex, "Error reading CSV headers");
return GetPreconfiguredItems(); return GetPreconfiguredItems();
} }
@ -181,11 +181,11 @@ public class CatalogContextSeed
.Skip(1) // skip header row .Skip(1) // skip header row
.Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)")) .Select(row => Regex.Split(row, ",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"))
.SelectTry(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup)) .SelectTry(column => CreateCatalogItem(column, csvheaders, catalogTypeIdLookup, catalogBrandIdLookup))
.OnCaughtException(ex => { logger.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; }) .OnCaughtException(ex => { logger.LogError(ex, "Error creating catalog item while seeding database"); return null; })
.Where(x => x != null); .Where(x => x != null);
} }
private CatalogItem CreateCatalogItem(string[] column, string[] headers, Dictionary<String, int> catalogTypeIdLookup, Dictionary<String, int> catalogBrandIdLookup) private CatalogItem CreateCatalogItem(string[] column, string[] headers, Dictionary<string, int> catalogTypeIdLookup, Dictionary<string, int> catalogBrandIdLookup)
{ {
if (column.Count() != headers.Count()) if (column.Count() != headers.Count())
{ {
@ -205,7 +205,7 @@ public class CatalogContextSeed
} }
string priceString = column[Array.IndexOf(headers, "price")].Trim('"').Trim(); string priceString = column[Array.IndexOf(headers, "price")].Trim('"').Trim();
if (!Decimal.TryParse(priceString, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out Decimal price)) if (!decimal.TryParse(priceString, NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out decimal price))
{ {
throw new Exception($"price={priceString}is not a valid decimal number"); throw new Exception($"price={priceString}is not a valid decimal number");
} }
@ -224,7 +224,7 @@ public class CatalogContextSeed
if (availableStockIndex != -1) if (availableStockIndex != -1)
{ {
string availableStockString = column[availableStockIndex].Trim('"').Trim(); string availableStockString = column[availableStockIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(availableStockString)) if (!string.IsNullOrEmpty(availableStockString))
{ {
if (int.TryParse(availableStockString, out int availableStock)) if (int.TryParse(availableStockString, out int availableStock))
{ {
@ -241,7 +241,7 @@ public class CatalogContextSeed
if (restockThresholdIndex != -1) if (restockThresholdIndex != -1)
{ {
string restockThresholdString = column[restockThresholdIndex].Trim('"').Trim(); string restockThresholdString = column[restockThresholdIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(restockThresholdString)) if (!string.IsNullOrEmpty(restockThresholdString))
{ {
if (int.TryParse(restockThresholdString, out int restockThreshold)) if (int.TryParse(restockThresholdString, out int restockThreshold))
{ {
@ -258,7 +258,7 @@ public class CatalogContextSeed
if (maxStockThresholdIndex != -1) if (maxStockThresholdIndex != -1)
{ {
string maxStockThresholdString = column[maxStockThresholdIndex].Trim('"').Trim(); string maxStockThresholdString = column[maxStockThresholdIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(maxStockThresholdString)) if (!string.IsNullOrEmpty(maxStockThresholdString))
{ {
if (int.TryParse(maxStockThresholdString, out int maxStockThreshold)) if (int.TryParse(maxStockThresholdString, out int maxStockThreshold))
{ {
@ -275,7 +275,7 @@ public class CatalogContextSeed
if (onReorderIndex != -1) if (onReorderIndex != -1)
{ {
string onReorderString = column[onReorderIndex].Trim('"').Trim(); string onReorderString = column[onReorderIndex].Trim('"').Trim();
if (!String.IsNullOrEmpty(onReorderString)) if (!string.IsNullOrEmpty(onReorderString))
{ {
if (bool.TryParse(onReorderString, out bool onReorder)) if (bool.TryParse(onReorderString, out bool onReorder))
{ {
@ -361,7 +361,7 @@ public class CatalogContextSeed
sleepDurationProvider: retry => TimeSpan.FromSeconds(5), sleepDurationProvider: retry => TimeSpan.FromSeconds(5),
onRetry: (exception, timeSpan, retry, ctx) => onRetry: (exception, timeSpan, retry, ctx) =>
{ {
logger.LogWarning(exception, "[{prefix}] Exception {ExceptionType} with message {Message} detected on attempt {retry} of {retries}", prefix, exception.GetType().Name, exception.Message, retry, retries); logger.LogWarning(exception, "[{prefix}] Error seeding database (attempt {retry} of {retries})", prefix, retry, retries);
} }
); );
} }

View File

@ -26,7 +26,7 @@ public class CatalogIntegrationEventService : ICatalogIntegrationEventService, I
{ {
try try
{ {
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId_published} - ({@IntegrationEvent})", evt.Id, evt); _logger.LogInformation("Publishing integration event: {IntegrationEventId_published} - ({@IntegrationEvent})", evt.Id, evt);
await _eventLogService.MarkEventAsInProgressAsync(evt.Id); await _eventLogService.MarkEventAsInProgressAsync(evt.Id);
_eventBus.Publish(evt); _eventBus.Publish(evt);
@ -34,14 +34,14 @@ public class CatalogIntegrationEventService : ICatalogIntegrationEventService, I
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "ERROR Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", evt.Id, evt); _logger.LogError(ex, "Error Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", evt.Id, evt);
await _eventLogService.MarkEventAsFailedAsync(evt.Id); await _eventLogService.MarkEventAsFailedAsync(evt.Id);
} }
} }
public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt) public async Task SaveEventAndCatalogContextChangesAsync(IntegrationEvent evt)
{ {
_logger.LogInformation("----- CatalogIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id); _logger.LogInformation("CatalogIntegrationEventService - Saving changes and integrationEvent: {IntegrationEventId}", evt.Id);
//Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction(): //Use of an EF Core resiliency strategy when using multiple DbContexts within an explicit BeginTransaction():
//See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency //See: https://docs.microsoft.com/en-us/ef/core/miscellaneous/connection-resiliency

View File

@ -21,7 +21,7 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>(); var confirmedOrderStockItems = new List<ConfirmedOrderStockItem>();

View File

@ -18,7 +18,7 @@ public class OrderStatusChangedToPaidIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
//we're not blocking stock/inventory //we're not blocking stock/inventory
foreach (var orderStockItem in @event.OrderStockItems) foreach (var orderStockItem in @event.OrderStockItems)

View File

@ -1,4 +1,4 @@
namespace Microsoft.AspNetCore.Hosting namespace Microsoft.AspNetCore.Hosting
{ {
public static class IWebHostExtensions public static class IWebHostExtensions
{ {
@ -35,7 +35,7 @@ namespace Microsoft.AspNetCore.Hosting
sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), sleepDurationProvider: retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)),
onRetry: (exception, timeSpan, retry, ctx) => onRetry: (exception, timeSpan, retry, ctx) =>
{ {
logger.LogWarning(exception, "[{prefix}] Exception {ExceptionType} with message {Message} detected on attempt {retry} of {retries}", nameof(TContext), exception.GetType().Name, exception.Message, retry, retries); logger.LogWarning(exception, "[{prefix}] Error seeding database (attempt {retry} of {retries})", nameof(TContext), retry, retries);
}); });
//if the sql server container is not created on run docker compose this //if the sql server container is not created on run docker compose this

View File

@ -10,7 +10,7 @@ public class LoginViewModel : LoginInputModel
public bool EnableLocalLogin { get; set; } = true; public bool EnableLocalLogin { get; set; } = true;
public IEnumerable<ExternalProvider> ExternalProviders { get; set; } = Enumerable.Empty<ExternalProvider>(); public IEnumerable<ExternalProvider> ExternalProviders { get; set; } = Enumerable.Empty<ExternalProvider>();
public IEnumerable<ExternalProvider> VisibleExternalProviders => ExternalProviders.Where(x => !String.IsNullOrWhiteSpace(x.DisplayName)); public IEnumerable<ExternalProvider> VisibleExternalProviders => ExternalProviders.Where(x => !string.IsNullOrWhiteSpace(x.DisplayName));
public bool IsExternalLoginOnly => EnableLocalLogin == false && ExternalProviders?.Count() == 1; public bool IsExternalLoginOnly => EnableLocalLogin == false && ExternalProviders?.Count() == 1;
public string ExternalLoginScheme => IsExternalLoginOnly ? ExternalProviders?.SingleOrDefault()?.AuthenticationScheme : null; public string ExternalLoginScheme => IsExternalLoginOnly ? ExternalProviders?.SingleOrDefault()?.AuthenticationScheme : null;

View File

@ -217,7 +217,7 @@ public class ConsentController : Controller
public ScopeViewModel CreateScopeViewModel(ParsedScopeValue parsedScopeValue, ApiScope apiScope, bool check) public ScopeViewModel CreateScopeViewModel(ParsedScopeValue parsedScopeValue, ApiScope apiScope, bool check)
{ {
var displayName = apiScope.DisplayName ?? apiScope.Name; var displayName = apiScope.DisplayName ?? apiScope.Name;
if (!String.IsNullOrWhiteSpace(parsedScopeValue.ParsedParameter)) if (!string.IsNullOrWhiteSpace(parsedScopeValue.ParsedParameter))
{ {
displayName += ":" + parsedScopeValue.ParsedParameter; displayName += ":" + parsedScopeValue.ParsedParameter;
} }

View File

@ -1,4 +1,4 @@
namespace Microsoft.eShopOnContainers.Services.Identity.API; namespace Microsoft.eShopOnContainers.Services.Identity.API;
public class SeedData public class SeedData
{ {
@ -104,16 +104,7 @@ public class SeedData
return Policy.Handle<Exception>(). return Policy.Handle<Exception>().
WaitAndRetryForeverAsync( WaitAndRetryForeverAsync(
sleepDurationProvider: retry => TimeSpan.FromSeconds(5), sleepDurationProvider: retry => TimeSpan.FromSeconds(5),
onRetry: (exception, retry, timeSpan) => onRetry: (exception, retry, timeSpan) => logger.LogWarning(exception, "Error migrating database (retry attempt {retry})", retry));
{
logger.LogWarning(
exception,
"Exception {ExceptionType} with message {Message} detected during database migration (retry attempt {retry})",
exception.GetType().Name,
exception.Message,
retry);
}
);
} }
return Policy.NoOpAsync(); return Policy.NoOpAsync();

View File

@ -6,9 +6,9 @@ public class LoggingBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest,
public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken) public async Task<TResponse> Handle(TRequest request, RequestHandlerDelegate<TResponse> next, CancellationToken cancellationToken)
{ {
_logger.LogInformation("----- Handling command {CommandName} ({@Command})", request.GetGenericTypeName(), request); _logger.LogInformation("Handling command {CommandName} ({@Command})", request.GetGenericTypeName(), request);
var response = await next(); var response = await next();
_logger.LogInformation("----- Command {CommandName} handled - response: {@Response}", request.GetGenericTypeName(), response); _logger.LogInformation("Command {CommandName} handled - response: {@Response}", request.GetGenericTypeName(), response);
return response; return response;
} }

View File

@ -38,11 +38,11 @@ public class TransactionBehavior<TRequest, TResponse> : IPipelineBehavior<TReque
await using var transaction = await _dbContext.BeginTransactionAsync(); await using var transaction = await _dbContext.BeginTransactionAsync();
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("TransactionContext", transaction.TransactionId) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("TransactionContext", transaction.TransactionId) }))
{ {
_logger.LogInformation("----- Begin transaction {TransactionId} for {CommandName} ({@Command})", transaction.TransactionId, typeName, request); _logger.LogInformation("Begin transaction {TransactionId} for {CommandName} ({@Command})", transaction.TransactionId, typeName, request);
response = await next(); response = await next();
_logger.LogInformation("----- Commit transaction {TransactionId} for {CommandName}", transaction.TransactionId, typeName); _logger.LogInformation("Commit transaction {TransactionId} for {CommandName}", transaction.TransactionId, typeName);
await _dbContext.CommitTransactionAsync(transaction); await _dbContext.CommitTransactionAsync(transaction);
@ -56,7 +56,7 @@ public class TransactionBehavior<TRequest, TResponse> : IPipelineBehavior<TReque
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "ERROR Handling transaction for {CommandName} ({@Command})", typeName, request); _logger.LogError(ex, "Error Handling transaction for {CommandName} ({@Command})", typeName, request);
throw; throw;
} }

View File

@ -15,7 +15,7 @@ public class ValidatorBehavior<TRequest, TResponse> : IPipelineBehavior<TRequest
{ {
var typeName = request.GetGenericTypeName(); var typeName = request.GetGenericTypeName();
_logger.LogInformation("----- Validating command {CommandType}", typeName); _logger.LogInformation("Validating command {CommandType}", typeName);
var failures = _validators var failures = _validators
.Select(v => v.Validate(request)) .Select(v => v.Validate(request))

View File

@ -44,7 +44,7 @@ public class CreateOrderCommandHandler
order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units); order.AddOrderItem(item.ProductId, item.ProductName, item.UnitPrice, item.Discount, item.PictureUrl, item.Units);
} }
_logger.LogInformation("----- Creating Order - Order: {@Order}", order); _logger.LogInformation("Creating Order - Order: {@Order}", order);
_orderRepository.Add(order); _orderRepository.Add(order);

View File

@ -77,7 +77,7 @@ public abstract class IdentifiedCommandHandler<T, R> : IRequestHandler<Identifie
} }
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
commandName, commandName,
idProperty, idProperty,
commandId, commandId,
@ -87,7 +87,7 @@ public abstract class IdentifiedCommandHandler<T, R> : IRequestHandler<Identifie
var result = await _mediator.Send(command, cancellationToken); var result = await _mediator.Send(command, cancellationToken);
_logger.LogInformation( _logger.LogInformation(
"----- Command result: {@Result} - {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Command result: {@Result} - {CommandName} - {IdProperty}: {CommandId} ({@Command})",
result, result,
commandName, commandName,
idProperty, idProperty,

View File

@ -25,12 +25,12 @@ public class GracePeriodConfirmedIntegrationEventHandler : IIntegrationEventHand
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId); var command = new SetAwaitingValidationOrderStatusCommand(@event.OrderId);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
command.GetGenericTypeName(), command.GetGenericTypeName(),
nameof(command.OrderNumber), nameof(command.OrderNumber),
command.OrderNumber, command.OrderNumber,

View File

@ -18,12 +18,12 @@ public class OrderPaymentFailedIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var command = new CancelOrderCommand(@event.OrderId); var command = new CancelOrderCommand(@event.OrderId);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
command.GetGenericTypeName(), command.GetGenericTypeName(),
nameof(command.OrderNumber), nameof(command.OrderNumber),
command.OrderNumber, command.OrderNumber,

View File

@ -18,12 +18,12 @@ public class OrderPaymentSucceededIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var command = new SetPaidOrderStatusCommand(@event.OrderId); var command = new SetPaidOrderStatusCommand(@event.OrderId);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
command.GetGenericTypeName(), command.GetGenericTypeName(),
nameof(command.OrderNumber), nameof(command.OrderNumber),
command.OrderNumber, command.OrderNumber,

View File

@ -18,12 +18,12 @@ public class OrderStockConfirmedIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId); var command = new SetStockConfirmedOrderStatusCommand(@event.OrderId);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
command.GetGenericTypeName(), command.GetGenericTypeName(),
nameof(command.OrderNumber), nameof(command.OrderNumber),
command.OrderNumber, command.OrderNumber,

View File

@ -16,7 +16,7 @@ public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandle
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var orderStockRejectedItems = @event.OrderStockItems var orderStockRejectedItems = @event.OrderStockItems
.FindAll(c => !c.HasStock) .FindAll(c => !c.HasStock)
@ -26,7 +26,7 @@ public class OrderStockRejectedIntegrationEventHandler : IIntegrationEventHandle
var command = new SetStockRejectedOrderStatusCommand(@event.OrderId, orderStockRejectedItems); var command = new SetStockRejectedOrderStatusCommand(@event.OrderId, orderStockRejectedItems);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
command.GetGenericTypeName(), command.GetGenericTypeName(),
nameof(command.OrderNumber), nameof(command.OrderNumber),
command.OrderNumber, command.OrderNumber,

View File

@ -26,7 +26,7 @@ public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHand
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
var result = false; var result = false;
@ -42,7 +42,7 @@ public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHand
var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, @event.RequestId); var requestCreateOrder = new IdentifiedCommand<CreateOrderCommand, bool>(createOrderCommand, @event.RequestId);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
requestCreateOrder.GetGenericTypeName(), requestCreateOrder.GetGenericTypeName(),
nameof(requestCreateOrder.Id), nameof(requestCreateOrder.Id),
requestCreateOrder.Id, requestCreateOrder.Id,
@ -52,7 +52,7 @@ public class UserCheckoutAcceptedIntegrationEventHandler : IIntegrationEventHand
if (result) if (result)
{ {
_logger.LogInformation("----- CreateOrderCommand suceeded - RequestId: {RequestId}", @event.RequestId); _logger.LogInformation("CreateOrderCommand suceeded - RequestId: {RequestId}", @event.RequestId);
} }
else else
{ {

View File

@ -27,7 +27,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
foreach (var logEvt in pendingLogEvents) foreach (var logEvt in pendingLogEvents)
{ {
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", logEvt.EventId, logEvt.IntegrationEvent); _logger.LogInformation("Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", logEvt.EventId, logEvt.IntegrationEvent);
try try
{ {
@ -37,7 +37,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "ERROR publishing integration event: {IntegrationEventId}", logEvt.EventId); _logger.LogError(ex, "Error publishing integration event: {IntegrationEventId}", logEvt.EventId);
await _eventLogService.MarkEventAsFailedAsync(logEvt.EventId); await _eventLogService.MarkEventAsFailedAsync(logEvt.EventId);
} }
@ -46,7 +46,7 @@ public class OrderingIntegrationEventService : IOrderingIntegrationEventService
public async Task AddAndSaveEventAsync(IntegrationEvent evt) public async Task AddAndSaveEventAsync(IntegrationEvent evt)
{ {
_logger.LogInformation("----- Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt); _logger.LogInformation("Enqueuing integration event {IntegrationEventId} to repository ({@IntegrationEvent})", evt.Id, evt);
await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction()); await _eventLogService.SaveEventAsync(evt, _orderingContext.GetCurrentTransaction());
} }

View File

@ -6,6 +6,6 @@ public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
{ {
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found"); RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("INSTANCE CREATED - {ClassName}", GetType().Name);
} }
} }

View File

@ -18,7 +18,7 @@ public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
RuleFor(command => command.CardTypeId).NotEmpty(); RuleFor(command => command.CardTypeId).NotEmpty();
RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found"); RuleFor(command => command.OrderItems).Must(ContainOrderItems).WithMessage("No order items found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("INSTANCE CREATED - {ClassName}", GetType().Name);
} }
private bool BeValidExpirationDate(DateTime dateTime) private bool BeValidExpirationDate(DateTime dateTime)

View File

@ -6,6 +6,6 @@ public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<Cr
{ {
RuleFor(command => command.Id).NotEmpty(); RuleFor(command => command.Id).NotEmpty();
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("INSTANCE CREATED - {ClassName}", GetType().Name);
} }
} }

View File

@ -6,6 +6,6 @@ public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
{ {
RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found"); RuleFor(order => order.OrderNumber).NotEmpty().WithMessage("No orderId found");
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name); logger.LogTrace("INSTANCE CREATED - {ClassName}", GetType().Name);
} }
} }

View File

@ -40,7 +40,7 @@ public class OrdersController : ControllerBase
var requestCancelOrder = new IdentifiedCommand<CancelOrderCommand, bool>(command, guid); var requestCancelOrder = new IdentifiedCommand<CancelOrderCommand, bool>(command, guid);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
requestCancelOrder.GetGenericTypeName(), requestCancelOrder.GetGenericTypeName(),
nameof(requestCancelOrder.Command.OrderNumber), nameof(requestCancelOrder.Command.OrderNumber),
requestCancelOrder.Command.OrderNumber, requestCancelOrder.Command.OrderNumber,
@ -70,7 +70,7 @@ public class OrdersController : ControllerBase
var requestShipOrder = new IdentifiedCommand<ShipOrderCommand, bool>(command, guid); var requestShipOrder = new IdentifiedCommand<ShipOrderCommand, bool>(command, guid);
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
requestShipOrder.GetGenericTypeName(), requestShipOrder.GetGenericTypeName(),
nameof(requestShipOrder.Command.OrderNumber), nameof(requestShipOrder.Command.OrderNumber),
requestShipOrder.Command.OrderNumber, requestShipOrder.Command.OrderNumber,
@ -132,7 +132,7 @@ public class OrdersController : ControllerBase
public async Task<ActionResult<OrderDraftDTO>> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand) public async Task<ActionResult<OrderDraftDTO>> CreateOrderDraftFromBasketDataAsync([FromBody] CreateOrderDraftCommand createOrderDraftCommand)
{ {
_logger.LogInformation( _logger.LogInformation(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
createOrderDraftCommand.GetGenericTypeName(), createOrderDraftCommand.GetGenericTypeName(),
nameof(createOrderDraftCommand.BuyerId), nameof(createOrderDraftCommand.BuyerId),
createOrderDraftCommand.BuyerId, createOrderDraftCommand.BuyerId,

View File

@ -20,7 +20,7 @@ public class OrderingService : OrderingGrpc.OrderingGrpcBase
{ {
_logger.LogInformation("Begin grpc call from method {Method} for ordering get order draft {CreateOrderDraftCommand}", context.Method, createOrderDraftCommand); _logger.LogInformation("Begin grpc call from method {Method} for ordering get order draft {CreateOrderDraftCommand}", context.Method, createOrderDraftCommand);
_logger.LogTrace( _logger.LogTrace(
"----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", "Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})",
createOrderDraftCommand.GetGenericTypeName(), createOrderDraftCommand.GetGenericTypeName(),
nameof(createOrderDraftCommand.BuyerId), nameof(createOrderDraftCommand.BuyerId),
createOrderDraftCommand.BuyerId, createOrderDraftCommand.BuyerId,

View File

@ -59,7 +59,7 @@ public class OrderingContextSeed
} }
catch (Exception ex) catch (Exception ex)
{ {
log.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); log.LogError(ex, "Error reading CSV headers");
return GetPredefinedCardTypes(); return GetPredefinedCardTypes();
} }
@ -67,13 +67,13 @@ public class OrderingContextSeed
return File.ReadAllLines(csvFileCardTypes) return File.ReadAllLines(csvFileCardTypes)
.Skip(1) // skip header column .Skip(1) // skip header column
.SelectTry(x => CreateCardType(x, ref id)) .SelectTry(x => CreateCardType(x, ref id))
.OnCaughtException(ex => { log.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; }) .OnCaughtException(ex => { log.LogError(ex, "Error creating card while seeding database"); return null; })
.Where(x => x != null); .Where(x => x != null);
} }
private CardType CreateCardType(string value, ref int id) private CardType CreateCardType(string value, ref int id)
{ {
if (String.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
throw new Exception("Orderstatus is null or empty"); throw new Exception("Orderstatus is null or empty");
} }
@ -103,7 +103,7 @@ public class OrderingContextSeed
} }
catch (Exception ex) catch (Exception ex)
{ {
log.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); log.LogError(ex, "Error reading CSV headers");
return GetPredefinedOrderStatus(); return GetPredefinedOrderStatus();
} }
@ -111,13 +111,13 @@ public class OrderingContextSeed
return File.ReadAllLines(csvFileOrderStatus) return File.ReadAllLines(csvFileOrderStatus)
.Skip(1) // skip header row .Skip(1) // skip header row
.SelectTry(x => CreateOrderStatus(x, ref id)) .SelectTry(x => CreateOrderStatus(x, ref id))
.OnCaughtException(ex => { log.LogError(ex, "EXCEPTION ERROR: {Message}", ex.Message); return null; }) .OnCaughtException(ex => { log.LogError(ex, "Error creating order status while seeding database"); return null; })
.Where(x => x != null); .Where(x => x != null);
} }
private OrderStatus CreateOrderStatus(string value, ref int id) private OrderStatus CreateOrderStatus(string value, ref int id)
{ {
if (String.IsNullOrEmpty(value)) if (string.IsNullOrEmpty(value))
{ {
throw new Exception("Orderstatus is null or empty"); throw new Exception("Orderstatus is null or empty");
} }
@ -167,7 +167,7 @@ public class OrderingContextSeed
sleepDurationProvider: retry => TimeSpan.FromSeconds(5), sleepDurationProvider: retry => TimeSpan.FromSeconds(5),
onRetry: (exception, timeSpan, retry, ctx) => onRetry: (exception, timeSpan, retry, ctx) =>
{ {
logger.LogWarning(exception, "[{prefix}] Exception {ExceptionType} with message {Message} detected on attempt {retry} of {retries}", prefix, exception.GetType().Name, exception.Message, retry, retries); logger.LogWarning(exception, "[{prefix}] Error seeding database (attempt {retry} of {retries})", prefix, retry, retries);
} }
); );
} }

View File

@ -52,7 +52,7 @@ namespace Ordering.BackgroundTasks.Services
{ {
var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId); var confirmGracePeriodEvent = new GracePeriodConfirmedIntegrationEvent(orderId);
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", confirmGracePeriodEvent.Id, confirmGracePeriodEvent); _logger.LogInformation("Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", confirmGracePeriodEvent.Id, confirmGracePeriodEvent);
_eventBus.Publish(confirmGracePeriodEvent); _eventBus.Publish(confirmGracePeriodEvent);
} }
@ -74,7 +74,7 @@ namespace Ordering.BackgroundTasks.Services
} }
catch (SqlException exception) catch (SqlException exception)
{ {
_logger.LogCritical(exception, "FATAL ERROR: Database connections could not be opened: {Message}", exception.Message); _logger.LogCritical(exception, "Fatal error establishing database connection");
} }

View File

@ -4,11 +4,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.Domain.AggregatesModel.O
public class Address : ValueObject public class Address : ValueObject
{ {
public String Street { get; private set; } public string Street { get; private set; }
public String City { get; private set; } public string City { get; private set; }
public String State { get; private set; } public string State { get; private set; }
public String Country { get; private set; } public string Country { get; private set; }
public String ZipCode { get; private set; } public string ZipCode { get; private set; }
public Address() { } public Address() { }

View File

@ -23,11 +23,11 @@ public class OrderStatus
public static OrderStatus FromName(string name) public static OrderStatus FromName(string name)
{ {
var state = List() var state = List()
.SingleOrDefault(s => String.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase)); .SingleOrDefault(s => string.Equals(s.Name, name, StringComparison.CurrentCultureIgnoreCase));
if (state == null) if (state == null)
{ {
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}"); throw new OrderingDomainException($"Possible values for OrderStatus: {string.Join(",", List().Select(s => s.Name))}");
} }
return state; return state;
@ -39,7 +39,7 @@ public class OrderStatus
if (state == null) if (state == null)
{ {
throw new OrderingDomainException($"Possible values for OrderStatus: {String.Join(",", List().Select(s => s.Name))}"); throw new OrderingDomainException($"Possible values for OrderStatus: {string.Join(",", List().Select(s => s.Name))}");
} }
return state; return state;

View File

@ -18,7 +18,7 @@ public class OrderStatusChangedToAwaitingValidationIntegrationEventHandler : IIn
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _hubContext.Clients await _hubContext.Clients
.Group(@event.BuyerName) .Group(@event.BuyerName)

View File

@ -20,7 +20,7 @@ public class OrderStatusChangedToCancelledIntegrationEventHandler : IIntegration
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _hubContext.Clients await _hubContext.Clients
.Group(@event.BuyerName) .Group(@event.BuyerName)

View File

@ -20,7 +20,7 @@ public class OrderStatusChangedToPaidIntegrationEventHandler : IIntegrationEvent
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _hubContext.Clients await _hubContext.Clients
.Group(@event.BuyerName) .Group(@event.BuyerName)

View File

@ -17,7 +17,7 @@ public class OrderStatusChangedToShippedIntegrationEventHandler : IIntegrationEv
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _hubContext.Clients await _hubContext.Clients
.Group(@event.BuyerName) .Group(@event.BuyerName)

View File

@ -21,7 +21,7 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _hubContext.Clients await _hubContext.Clients
.Group(@event.BuyerName) .Group(@event.BuyerName)

View File

@ -21,7 +21,7 @@ public class OrderStatusChangedToSubmittedIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
await _hubContext.Clients await _hubContext.Clients
.Group(@event.BuyerName) .Group(@event.BuyerName)

View File

@ -42,7 +42,7 @@ public class OrdersWebApiTest
//Act //Act
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object, _loggerMock.Object); var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object, _loggerMock.Object);
var actionResult = await orderController.CancelOrderAsync(new CancelOrderCommand(1), String.Empty) as BadRequestResult; var actionResult = await orderController.CancelOrderAsync(new CancelOrderCommand(1), string.Empty) as BadRequestResult;
//Assert //Assert
Assert.Equal((int)System.Net.HttpStatusCode.BadRequest, actionResult.StatusCode); Assert.Equal((int)System.Net.HttpStatusCode.BadRequest, actionResult.StatusCode);
@ -73,7 +73,7 @@ public class OrdersWebApiTest
//Act //Act
var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object, _loggerMock.Object); var orderController = new OrdersController(_mediatorMock.Object, _orderQueriesMock.Object, _identityServiceMock.Object, _loggerMock.Object);
var actionResult = await orderController.ShipOrderAsync(new ShipOrderCommand(1), String.Empty) as BadRequestResult; var actionResult = await orderController.ShipOrderAsync(new ShipOrderCommand(1), string.Empty) as BadRequestResult;
//Assert //Assert
Assert.Equal((int)System.Net.HttpStatusCode.BadRequest, actionResult.StatusCode); Assert.Equal((int)System.Net.HttpStatusCode.BadRequest, actionResult.StatusCode);

View File

@ -25,7 +25,7 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
{ {
using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) })) using (_logger.BeginScope(new List<KeyValuePair<string, object>> { new ("IntegrationEventContext", @event.Id) }))
{ {
_logger.LogInformation("----- Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event); _logger.LogInformation("Handling integration event: {IntegrationEventId} - ({@IntegrationEvent})", @event.Id, @event);
IntegrationEvent orderPaymentIntegrationEvent; IntegrationEvent orderPaymentIntegrationEvent;
@ -44,7 +44,7 @@ public class OrderStatusChangedToStockConfirmedIntegrationEventHandler :
orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId); orderPaymentIntegrationEvent = new OrderPaymentFailedIntegrationEvent(@event.OrderId);
} }
_logger.LogInformation("----- Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, orderPaymentIntegrationEvent); _logger.LogInformation("Publishing integration event: {IntegrationEventId} - ({@IntegrationEvent})", orderPaymentIntegrationEvent.Id, orderPaymentIntegrationEvent);
_eventBus.Publish(orderPaymentIntegrationEvent); _eventBus.Publish(orderPaymentIntegrationEvent);

View File

@ -16,7 +16,7 @@ public class AccountController : Controller
var user = User as ClaimsPrincipal; var user = User as ClaimsPrincipal;
var token = await HttpContext.GetTokenAsync("access_token"); var token = await HttpContext.GetTokenAsync("access_token");
_logger.LogInformation("----- User {@User} authenticated", user); _logger.LogInformation("User {@User} authenticated", user);
if (token != null) if (token != null)
{ {

View File

@ -21,7 +21,7 @@ public class BasicAuthenticationHeaderValue : AuthenticationHeaderValue
private static string EncodeCredential(string userName, string password) private static string EncodeCredential(string userName, string password)
{ {
Encoding encoding = Encoding.GetEncoding("iso-8859-1"); Encoding encoding = Encoding.GetEncoding("iso-8859-1");
string credential = String.Format("{0}:{1}", userName, password); string credential = string.Format("{0}:{1}", userName, password);
return Convert.ToBase64String(encoding.GetBytes(credential)); return Convert.ToBase64String(encoding.GetBytes(credential));
} }

View File

@ -51,13 +51,13 @@ public class WebContextSeed
} }
else else
{ {
logger.LogWarning("Skipped file '{FileName}' in zipfile '{ZipFileName}'", entry.Name, imagesZipFile); logger.LogWarning("Skipped file '{FileName}' in zip file '{ZipFileName}'", entry.Name, imagesZipFile);
} }
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
logger.LogError(ex, "ERROR in GetPreconfiguredImages: {Message}", ex.Message); logger.LogError(ex, "Error getting preconfigured images");
} }
} }
} }