Ejemplo n.º 1
0
        public ActionResult <CreatePaymentResponse> Create(CreatePaymentRequest request)
        {
            logger.LogInformation("CreatePaymentRequest");

            var timer = Stopwatch.StartNew();

            try
            {
                var paymentCreationData = request.ToPaymentCreationData();
                var result = paymentsProcessor.CreatePayment(paymentCreationData);

                if (result.IsSuccess)
                {
                    var response = new CreatePaymentResponse
                    {
                        PaymentId = result.PaymentId
                    };

                    var elapsed = timer.ElapsedMilliseconds; timer.Stop();

                    logger.LogInformation($"[action=CreatePayment] SUCCESS - [elapsed={elapsed}]");
                    MetricsDataCollector.IncreaseCreatedPayments();
                    MetricsDataCollector.LastPaymentCreationTime = elapsed;
                    return(Created($"payments/{result.PaymentId}", response));
                }
                else
                {
                    var elapsed = timer.ElapsedMilliseconds; timer.Stop();
                    logger.LogError($"[action=CreatePayment] FAILED - [elapsed={elapsed}] " + result.Error);
                    MetricsDataCollector.IncreaseFailedPayments();
                    MetricsDataCollector.IncreaseErrors();
                    return(BadRequest(result.Error));
                }
            }
            catch (Exception exc)
            {
                logger.LogError(exc, $"Failed to create Payment. Request: {request.ToLog()}");
                MetricsDataCollector.IncreaseErrors();
                return(GeneralError());
            }
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            var logger = NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();

            try
            {
                logger.Info("Application start");
                MetricsDataCollector.Initialize();
                CreateHostBuilder(args).Build().Run();
            }
            catch (Exception exception)
            {
                //NLog: catch setup errors
                logger.Error(exception, "Stopped program because of exception");
                throw;
            }
            finally
            {
                // Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
                NLog.LogManager.Shutdown();
            }
        }
Ejemplo n.º 3
0
        public ActionResult <PaymentResponse> Get([FromRoute] string paymentId)
        {
            logger.LogInformation("GetPayment");

            try
            {
                var payment = paymentsProcessor.GetPayment(paymentId);

                if (payment == null)
                {
                    return(new NotFoundObjectResult(null));
                }
                else
                {
                    return(PaymentResponse.FromPayment(payment));
                }
            }
            catch (Exception exc)
            {
                logger.LogError(exc, $"Failed to retrieve Payment. PaymentId: {paymentId}");
                MetricsDataCollector.IncreaseErrors();
                return(GeneralError());
            }
        }