コード例 #1
0
        } // End Constructor

        /*
         * Name: Index
         * Author: Namchok Singhachai
         * Description: A show of logs.
         */
        public async Task <IActionResult> Index()
        {
            try
            {
                _logger.LogTrace("Start logs index.");
                _logger.LogTrace("Finding user ID.");
                ViewData["UserId"] = User.FindFirstValue(ClaimTypes.NameIdentifier) ?? throw new Exception("The user ID not found!.");  // Get user ID
                _logger.LogDebug($"Getting top 100 from all logs.");
                ViewData["Logs"] = await _logs.GetAllAsync(100) ?? throw new Exception("Calling a method on a null object reference."); // Set result to view and check null value

                ViewData["INFO"] = @$ "toastr.info('Show the last 100 results.');";
                _logger.LogTrace("End logs index.");
                return(View());
            }
            catch (Exception e)
            {
                _logger.LogError(e.Message.ToString());
                TempData["Exception"] = @"Swal.fire({ icon: 'error', title: 'ERROR!', text: `" + e.Message.Replace("\\", "/").Replace("`", "'") + @"`, showConfirmButton: true });";
                _logger.LogTrace("End logs index.");
                return(View());
            } // End try catch
        }     // End Index
コード例 #2
0
        public async Task <ActionResult <IEnumerable <LogDto> > > GetAll()
        {
            var logs = await _logsRepository.GetAllAsync();

            var dtos = new List <LogDto>();

            foreach (var log in logs.OrderByDescending(o => o.Created))
            {
                dtos.Add(new LogDto
                {
                    Id       = log.Id,
                    Time     = log.Created.ToShortTimeString(),
                    Date     = log.Created.ToShortDateString(),
                    Type     = log.Type.ToString(),
                    Service  = log.ServiceName,
                    Category = log.Category,
                    Message  = log.Message
                });
            }

            return(Collection(dtos));
        }
コード例 #3
0
 public async Task <IEnumerable <Log> > GetAllLogsAsync()
 {
     return(await _logsRepository.GetAllAsync());
 }