Пример #1
0
        public async Task <IActionResult> GetLogs(int?pageSize = 10, int?pageNumber = 1, string name = null)
        {
            var response = new ListModelResponse <LogListModel>() as IListModelResponse <LogListModel>;

            try
            {
                response.PageSize   = (int)pageSize;
                response.PageNumber = (int)pageNumber;

                var query = await _loggingService.GetLogsAsync(response.PageSize, response.PageNumber, name);

                var result = query.Select(x => new LogListModel()
                {
                    Id = x.Id,
                    MessageTemplate = x.MessageTemplate,
                    TimeStamp       = x.TimeStamp,
                    Message         = x.Message,
                    Exception       = x.Exception,
                    Level           = x.Level,
                    LogEvent        = x.LogEvent,
                    Properties      = x.Properties,
                }).ToList();

                response.Model   = result;
                response.Message = string.Format("Total of records: {0}", response.Model.Count());

                if (!response.Model.Any())
                {
                    _logger.Warning(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.LIST_ITEMS_NOTFOUND, "LIST_ITEMS_NOTFOUND", RequestPath());

                    response.HasError     = true;
                    response.ErrorMessage = "LIST_ITEMS_NOTFOUND";
                    response.ErrorCode    = LoggingEvents.LIST_ITEMS_NOTFOUND;
                    return(response.ToHttpResponse());
                }
            }
            catch (Exception ex)
            {
                _logger.Warning(MessageTemplate, ProtocolName(), RequestMethod(), TraceIdentifierName(), LoggingEvents.METHOD_ERROR, "METHOD_ERROR", RequestPath());

                response.HasError     = true;
                response.ErrorMessage = ex.Message;
            }

            return(response.ToHttpResponse());
        }