Exemple #1
0
        public async Task <ActionResult> GetCoffeeById(string coffeeId)
        {
            try
            {
                using (_cofeelogger.BeginScope($"API-GetCoffeeById-Inititating {DateTime.UtcNow}"))
                {
                    _cofeelogger.LogInformation(LoggingEvents.GetItem, $"API-GetCoffeeById-Getting item by coffeeId {coffeeId}");

                    var result = await _coffeeService.GetCoffeeByDisplayId(coffeeId).ConfigureAwait(false);

                    if (result.statusCode == HttpStatusCode.NotFound)
                    {
                        _cofeelogger.LogInformation(LoggingEvents.GetItemNotFound, $"API-GetCoffeeById-Item by coffeeId  {coffeeId} not found");
                    }

                    _cofeelogger.LogInformation($"API-GetCoffeeById-Completed {DateTime.UtcNow}");

                    return(StatusCode((int)result.statusCode, result.coffeeDto));
                }
            }
            catch (Exception ex)
            {
                _cofeelogger.LogError
                    (ex,
                    $"API-GetCoffeeById-Exception {DateTime.UtcNow}"
                    );

                return(StatusCode((int)HttpStatusCode.BadRequest,
                                  _apiSettings.IsSecuredEnvironment ? "An error occured while processing GetCoffeeById" : ex.ToString()));
            }
        }