Merge pull request #1044 from dotnet-architecture/enhancement/add-validator-creation-log-traces

Add log traces
This commit is contained in:
Miguel Veloso 2019-05-16 19:10:58 +01:00 committed by GitHub
commit 93727c259c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 20 deletions

View File

@ -111,6 +111,7 @@ services:
- OrchestratorType=${ORCHESTRATOR_TYPE} - OrchestratorType=${ORCHESTRATOR_TYPE}
- UseLoadTest=${USE_LOADTEST:-False} - UseLoadTest=${USE_LOADTEST:-False}
- Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose - Serilog__MinimumLevel__Override__Microsoft.eShopOnContainers.BuildingBlocks.EventBusRabbitMQ=Verbose
- Serilog__MinimumLevel__Override__Ordering.API=Verbose
ports: ports:
- "5102:80" # Important: In a production environment your should remove the external port (5102) kept here for microservice debugging purposes. - "5102:80" # Important: In a production environment your should remove the external port (5102) kept here for microservice debugging purposes.
# The API Gateway redirects and access through the internal port (80). # The API Gateway redirects and access through the internal port (80).

View File

@ -1,17 +1,16 @@
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands; using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.Validations namespace Ordering.API.Application.Validations
{ {
public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand> public class CancelOrderCommandValidator : AbstractValidator<CancelOrderCommand>
{ {
public CancelOrderCommandValidator() public CancelOrderCommandValidator(ILogger<CancelOrderCommandValidator> logger)
{ {
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);
} }
} }
} }

View File

@ -1,5 +1,6 @@
using FluentValidation; using FluentValidation;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -9,19 +10,21 @@ namespace Ordering.API.Application.Validations
{ {
public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand> public class CreateOrderCommandValidator : AbstractValidator<CreateOrderCommand>
{ {
public CreateOrderCommandValidator() public CreateOrderCommandValidator(ILogger<CreateOrderCommandValidator> logger)
{ {
RuleFor(command => command.City).NotEmpty(); RuleFor(command => command.City).NotEmpty();
RuleFor(command => command.Street).NotEmpty(); RuleFor(command => command.Street).NotEmpty();
RuleFor(command => command.State).NotEmpty(); RuleFor(command => command.State).NotEmpty();
RuleFor(command => command.Country).NotEmpty(); RuleFor(command => command.Country).NotEmpty();
RuleFor(command => command.ZipCode).NotEmpty(); RuleFor(command => command.ZipCode).NotEmpty();
RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19); RuleFor(command => command.CardNumber).NotEmpty().Length(12, 19);
RuleFor(command => command.CardHolderName).NotEmpty(); RuleFor(command => command.CardHolderName).NotEmpty();
RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date"); RuleFor(command => command.CardExpiration).NotEmpty().Must(BeValidExpirationDate).WithMessage("Please specify a valid card expiration date");
RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3); RuleFor(command => command.CardSecurityNumber).NotEmpty().Length(3);
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);
} }
private bool BeValidExpirationDate(DateTime dateTime) private bool BeValidExpirationDate(DateTime dateTime)
@ -34,4 +37,4 @@ namespace Ordering.API.Application.Validations
return orderItems.Any(); return orderItems.Any();
} }
} }
} }

View File

@ -1,13 +1,16 @@
using FluentValidation; using FluentValidation;
using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands; using Microsoft.eShopOnContainers.Services.Ordering.API.Application.Commands;
using Microsoft.Extensions.Logging;
namespace Ordering.API.Application.Validations namespace Ordering.API.Application.Validations
{ {
public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand,bool>> public class IdentifiedCommandValidator : AbstractValidator<IdentifiedCommand<CreateOrderCommand,bool>>
{ {
public IdentifiedCommandValidator() public IdentifiedCommandValidator(ILogger<IdentifiedCommandValidator> logger)
{ {
RuleFor(command => command.Id).NotEmpty(); RuleFor(command => command.Id).NotEmpty();
logger.LogTrace("----- INSTANCE CREATED - {ClassName}", GetType().Name);
} }
} }
} }

View File

@ -1,17 +1,16 @@
using FluentValidation; using FluentValidation;
using Microsoft.Extensions.Logging;
using Ordering.API.Application.Commands; using Ordering.API.Application.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Ordering.API.Application.Validations namespace Ordering.API.Application.Validations
{ {
public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand> public class ShipOrderCommandValidator : AbstractValidator<ShipOrderCommand>
{ {
public ShipOrderCommandValidator() public ShipOrderCommandValidator(ILogger<ShipOrderCommandValidator> logger)
{ {
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);
} }
} }
} }