public async Task Handle(UserCreatedIntegrationEvent @event) { //Serilog的Sql Server配置的自定义字段部分,发生事件记录在数据库 using (LogContext.PushProperty("IntegrationEventContext", $"{@event.Id}-{Program.AppName}")) { //记录事件处理程序启动 _logger.LogInformation("----- Handling integration event: {IntegrationEventId} at {AppName} - ({@IntegrationEvent})", @event.Id, Program.AppName, @event); //这里写需要执行的命令 var command = new CreateUserCommand(@event.UserId); _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", command.GetGenericTypeName(), nameof(command.UserId), command.UserId, command); await _mediator.Send(command); } }
public async Task <IActionResult> AddUserInfoAsync([FromBody] CreateUserCommand createUserCommand) { bool commandResult = false; _logger.LogInformation( "----- Sending command: {CommandName} - {IdProperty}: {CommandId} ({@Command})", createUserCommand.GetGenericTypeName(), nameof(createUserCommand.UserId), createUserCommand.UserId, createUserCommand); commandResult = await _mediator.Send(createUserCommand); if (!commandResult) { return(BadRequest()); } return(Ok()); }