public void Insert(Customer customer) { try { var dbClient = new MongoClient("mongodb://127.0.0.1:27018"); var dbCustomer = dbClient.GetDatabase("customer"); var clCustomer = dbCustomer.GetCollection <Customer>("customer"); clCustomer.InsertOne(customer); } catch (Exception ex) { _logger.LogError("Erro ao tentar inserir", ex); throw; } }
public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken) { try { _logger.LogInformation("Starting processing request: {@Request}", typeof(TRequest).Name); var result = await _handler.Handle(request, cancellationToken); _logger.LogInformation("Finished processing request: {@Request}", typeof(TRequest).Name); return(result); } catch (Exception exception) { _logger.LogError("Error happened when processing request: {@Request}. Type of error: {@Exception}", typeof(TRequest).Name, exception.GetType().Name); throw; } }