Exemple #1
0
        public virtual IActionResult List()
        {
            //prepare model
            LogSearchModel model = _logModelFactory.PrepareLogSearchModel(new LogSearchModel());

            return(View(model));
        }
Exemple #2
0
        public Task <IEnumerable <ILogItem> > GetLogItems(LogSearchModel logSearchModel)
        {
            return(Task.Run(() => {
                using (var context = _contextFactory.CreateContext()) {
                    IQueryable <Log> q = context.Logs;
                    if (logSearchModel.LogType.HasValue)
                    {
                        q = q.Where(l => l.LogType == logSearchModel.LogType.Value);
                    }
                    if (logSearchModel.Age.HasValue)
                    {
                        q = q.Where(l => (l.LogDate - DateTime.Now) < logSearchModel.Age.Value);
                    }

                    q = q.OrderByDescending(l => l.LogDate);
                    if (logSearchModel.MaxCount.HasValue)
                    {
                        q = q.Take(logSearchModel.MaxCount.Value);
                    }

                    IEnumerable <ILogItem> result = q.ToList();
                    return result;
                }
            }));
        }
Exemple #3
0
        public virtual IActionResult LogList(LogSearchModel searchModel)
        {
            //prepare model
            LogListModel model = _logModelFactory.PrepareLogListModel(searchModel);

            return(Json(model));
        }
        /// <summary>
        /// Prepare paged log list model
        /// </summary>
        /// <param name="searchModel">Log search model</param>
        /// <returns>Log list model</returns>
        public virtual LogListModel PrepareLogListModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter log
            var createdOnFromValue = searchModel.CreatedOnFrom.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone) : null;
            var createdToFromValue = searchModel.CreatedOnTo.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;
            var logLevel = searchModel.LogLevelId > 0 ? (LogLevel?)searchModel.LogLevelId : null;

            //get log
            var logItems = _logger.GetAllLogs(message: searchModel.Message,
                                              fromUtc: createdOnFromValue,
                                              toUtc: createdToFromValue,
                                              logLevel: logLevel,
                                              pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new LogListModel
            {
                //fill in model values from the entity
                Data = logItems.Select(logItem =>
                {
                    //fill in model values from the entity
                    var logModel = new LogModel
                    {
                        Id          = logItem.Id,
                        IpAddress   = logItem.IpAddress,
                        CustomerId  = logItem.CustomerId,
                        PageUrl     = logItem.PageUrl,
                        ReferrerUrl = logItem.ReferrerUrl
                    };

                    //little performance optimization: ensure that "FullMessage" is not returned
                    logModel.FullMessage = string.Empty;

                    //convert dates to the user time
                    logModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    logModel.CustomerEmail = logItem.Customer?.Email;
                    logModel.LogLevel      = _localizationService.GetLocalizedEnum(logItem.LogLevel);
                    logModel.ShortMessage  = HtmlHelper.FormatText(logItem.ShortMessage, false, true, false, false, false, false);

                    return(logModel);
                }),
                Total = logItems.TotalCount
            };

            return(model);
        }
Exemple #5
0
        public async Task <IActionResult> LogList(LogSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSystemLog))
            {
                return(AccessDeniedKendoGridJson());
            }

            var model = await _logModelFactory.PrepareLogListModel(searchModel);

            return(Json(model));
        }
Exemple #6
0
        public virtual IActionResult LogList(LogSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageSystemLog))
            {
                return(AccessDeniedKendoGridJson());
            }

            //prepare model
            var model = _logModelFactory.PrepareLogListModel(searchModel);

            return(Json(model));
        }
        public IActionResult LogsList(LogSearchModel searchModel)
        {
            var logs = _loggerEntityService.GetLogs(out var totalResults, searchModel.SearchPhrase, searchModel.Current,
                                                    searchModel.RowCount);

            var models = logs.Select(x => _modelMapper.Map <LogModel>(x)).ToList();

            return(R.Success.WithGridResponse(totalResults, searchModel.Current, searchModel.RowCount)
                   .With("logs", models)
                   .WithParams(searchModel)
                   .Result);
        }
        public virtual async Task <IActionResult> LogList(LogSearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageSystemLog))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = await _logModelFactory.PrepareLogListModelAsync(searchModel);

            return(Json(model));
        }
Exemple #9
0
        public async Task <LogSearchModel> PrepareLogSearchModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            await _baseModelFactory.PrepareLogLevels(searchModel.AvailableLogLevels);

            searchModel.SetGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare log search model
        /// </summary>
        /// <param name="searchModel">Log search model</param>
        /// <returns>Log search model</returns>
        public virtual LogSearchModel PrepareLogSearchModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available log levels
            _baseAdminModelFactory.PrepareLogLevels(searchModel.AvailableLogLevels);

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
Exemple #11
0
        /// <summary>
        /// Prepare log search model
        /// </summary>
        /// <param name="searchModel">Log search model</param>
        /// <returns>Log search model</returns>
        public virtual LogSearchModel PrepareLogSearchModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare available log levels
            var availableLogLevelItems = LogLevel.Debug.ToSelectList(false);

            foreach (var logLevelItem in availableLogLevelItems)
            {
                searchModel.AvailableLogLevels.Add(logLevelItem);
            }

            return(searchModel);
        }
Exemple #12
0
        /// <summary>
        /// 日志列表
        /// </summary>
        /// <param name="moduleType">菜单类型</param>
        /// <returns></returns>
        public List <LogEntity> GetLogListByTime(Pagination pagination, string queryJson)
        {
            QueryRequest <LogEntity> request     = new QueryRequest <LogEntity>();
            LogSearchModel           searchModel = new LogSearchModel();
            DateTime logDate = DateTime.Now;

            //筛选条件
            if (!string.IsNullOrEmpty(queryJson))
            {
                searchModel = ApiHelper.JsonDeserial <LogSearchModel>(queryJson);
            }
            if (searchModel != null)
            {
                if (!string.IsNullOrEmpty(searchModel.keyWord))
                {
                    request.Expression = t => (t.Title.Contains(searchModel.keyWord) || t.Source.Contains(searchModel.keyWord));
                }
                if (searchModel.timeType > 0)
                {
                    if (searchModel.timeType == 2)
                    {
                        logDate = logDate.AddDays(-7);
                    }
                    else if (searchModel.timeType == 1)
                    {
                        logDate = (logDate.Year + "-" + logDate.Month + "-" + logDate.Day)._DateTime();
                    }
                    else if (searchModel.timeType == 3)
                    {
                        logDate = logDate.AddMonths(-1);
                    }
                    else if (searchModel.timeType == 4)
                    {
                        logDate = logDate.AddMonths(-3);
                    }
                    request.Expression = ((request.Expression == null) ? (t => t.CreateDate >= logDate) : request.Expression.And(t => t.CreateDate >= logDate));
                }
            }
            request.Page     = pagination.page;
            request.PageSize = pagination.rows;
            request.Sort     = "CreateDate desc";
            QueryResponse <LogEntity> response = _service.GetPageList(request);

            pagination.records = response.TotalCount;
            return(response.Items.ToList());
        }
Exemple #13
0
        /// <summary>
        /// Prepare paged log list model
        /// </summary>
        /// <param name="searchModel">Log search model</param>
        /// <returns>Log list model</returns>
        public virtual LogListModel PrepareLogListModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter log
            var createdOnFromValue = searchModel.CreatedOnFrom.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone) : null;
            var createdToFromValue = searchModel.CreatedOnTo.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1) : null;
            var logLevel = searchModel.LogLevelId > 0 ? (LogLevel?)searchModel.LogLevelId : null;

            //get log
            var logItems = _logger.GetAllLogs(message: searchModel.Message,
                                              fromUtc: createdOnFromValue,
                                              toUtc: createdToFromValue,
                                              logLevel: logLevel,
                                              pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new LogListModel().PrepareToGrid(searchModel, logItems, () =>
            {
                //fill in model values from the entity
                return(logItems.Select(logItem =>
                {
                    //fill in model values from the entity
                    var logModel = logItem.ToModel <LogModel>();

                    //convert dates to the user time
                    logModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    logModel.LogLevel = _localizationService.GetLocalizedEnum(logItem.LogLevel);
                    logModel.ShortMessage = HtmlHelper.FormatText(logItem.ShortMessage, false, true, false, false, false, false);
                    logModel.FullMessage = string.Empty;
                    logModel.CustomerEmail = _customerService.GetCustomerById(logItem.CustomerId ?? 0)?.Email ?? string.Empty;

                    return logModel;
                }));
            });

            return(model);
        }
Exemple #14
0
        /// <summary>
        /// Prepare paged log list model
        /// </summary>
        /// <param name="searchModel">Log search model</param>
        /// <returns>Log list model</returns>
        public virtual LogListModel PrepareLogListModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter log
            var createdOnFromValue = searchModel.CreatedOnFrom.HasValue
                ? (DateTime?)searchModel.CreatedOnFrom.Value : null;
            var createdToFromValue = searchModel.CreatedOnTo.HasValue
                ? (DateTime?)searchModel.CreatedOnTo.Value : null;
            var logLevel = searchModel.LogLevelId > 0 ? (LogLevel?)searchModel.LogLevelId : null;

            //get log
            var logItems = _logger.GetAllLogs(message: searchModel.Message,
                                              fromUtc: createdOnFromValue,
                                              toUtc: createdToFromValue,
                                              logLevel: logLevel,
                                              pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize);

            //prepare list model
            var model = new LogListModel().PrepareToGrid(searchModel, logItems, () =>
            {
                //fill in model values from the entity
                return(logItems.Select(logItem =>
                {
                    //fill in model values from the entity
                    var logModel = logItem.ToModel <LogModel>();

                    //convert dates to the user time
                    logModel.CreatedOn = logItem.CreatedOnUtc;

                    //fill in additional values (not existing in the entity)
                    logModel.LogLevel = logItem.LogLevel.ToString();
                    logModel.ShortMessage = logItem.ShortMessage;
                    logModel.FullMessage = string.Empty;
                    logModel.UserEmail = logItem.User?.Email ?? string.Empty;

                    return logModel;
                }));
            });

            return(model);
        }
Exemple #15
0
        public async Task <LogListModel> PrepareLogListModel(LogSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter log
            var createdOnFromValue = searchModel.CreatedOnFrom.HasValue
                ? (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value,
                                                              _dateTimeHelper.CurrentTimeZone)
                : null;
            var createdToFromValue = searchModel.CreatedOnTo.HasValue
                ? (DateTime?)_dateTimeHelper
                                     .ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1)
                : null;
            var logLevel = searchModel.LogLevelId > 0 ? (LogLevel?)searchModel.LogLevelId : null;

            var logItems = await _logger.GetAllLogs(message : searchModel.Message,
                                                    fromUtc : createdOnFromValue,
                                                    toUtc : createdToFromValue,
                                                    logLevel : logLevel,
                                                    pageIndex : searchModel.Page - 1, pageSize : searchModel.PageSize);

            //prepare list model
            var model = new LogListModel
            {
                Data = logItems.Select(logItem =>
                {
                    var logModel = logItem.ToModel <LogModel>();

                    logModel.CreatedOn    = _dateTimeHelper.ConvertToUserTime(logItem.CreatedOnUtc, DateTimeKind.Utc);
                    logModel.LogLevel     = CommonHelper.ConvertEnum(logItem.LogLevel.ToString());
                    logModel.ShortMessage = HtmlHelper.FormatText(logItem.ShortMessage, false, true, false, false, false, false);
                    logModel.FullMessage  = string.Empty;
                    logModel.UserEmail    = logItem.User?.Email ?? string.Empty;

                    return(logModel);
                }),
                Total = logItems.TotalCount
            };

            return(model);
        }
Exemple #16
0
        public ActionResult _GetLogs(LogSearchModel searchModel)
        {
            if (string.IsNullOrWhiteSpace(searchModel.UserEmail) &&
                searchModel.EventId == null)
            {
                ModelState.AddModelError("FilterOptions", "At least one filter option must be applied.");
            }

            if (!ModelState.IsValid)
            {
                return(Json(new { success = false, message = ModelState.GetErrors() }, JsonRequestBehavior.AllowGet));
            }

            var userEmail = searchModel.UserEmail?.Split('|')[1];

            var logs = LogServices.GetLogs(searchModel.EventId, userEmail, searchModel.DayRange);

            return(PartialView("_List", logs));
        }
Exemple #17
0
        public async Task <ActionResult> List()
        {
            var availableLevels = new List <SelectListItem>
            {
                new SelectListItem {
                    Text = "All", Value = ""
                },
                new SelectListItem {
                    Text = "Debug", Value = "Debug"
                },
                new SelectListItem {
                    Text = "Info", Value = "Info"
                },
                new SelectListItem {
                    Text = "Warn", Value = "Warn"
                },
                new SelectListItem {
                    Text = "Error", Value = "Error"
                },
                new SelectListItem {
                    Text = "Fatal", Value = "Fatal"
                },
            };
            var entities = await _logService.GetUsernames();

            var availableUsernames = entities.Select(x => new SelectListItem {
                Text = x, Value = x
            }).ToList();

            availableUsernames.Insert(0, new SelectListItem {
                Text = "All", Value = ""
            });
            availableUsernames.Insert(1, new SelectListItem {
                Text = "Not Available", Value = "NOT AVAILABLE"
            });
            var model = new LogSearchModel {
                AvailableLevels = availableLevels, AvailableUsernames = availableUsernames
            };

            return(View("List", model));
        }
Exemple #18
0
        public async Task <PagedModel <SysOperationLogDto> > SearchOperationLogs(LogSearchModel searchModel)
        {
            Expression <Func <SysOperationLog, bool> > whereCondition = x => true;

            if (searchModel.BeginTime.HasValue)
            {
                whereCondition = whereCondition.And(x => x.CreateTime >= searchModel.BeginTime.Value);
            }

            if (searchModel.EndTime.HasValue)
            {
                whereCondition = whereCondition.And(x => x.CreateTime <= searchModel.BeginTime.Value);
            }

            if (!string.IsNullOrWhiteSpace(searchModel.LogName))
            {
                whereCondition = whereCondition.And(x => x.LogName.Contains(searchModel.LogName));
            }

            if (!string.IsNullOrWhiteSpace(searchModel.LogType))
            {
                whereCondition = whereCondition.And(x => x.LogType == searchModel.LogType);
            }

            var pagedModel = await _operationLogRepository.PagedAsync(searchModel.PageIndex, searchModel.PageSize, whereCondition, x => x.ID, true);

            var result = _mapper.Map <PagedModel <SysOperationLogDto> >(pagedModel);

            if (result.Count > 0)
            {
                var userIds = result.Data.Select(x => x.UserId);
                var users   = await _userRepository.SelectAsync(x => userIds.Contains(x.ID));

                foreach (var log in result.Data)
                {
                    log.UserName = users.FirstOrDefault(x => x.ID == log.UserId)?.Name;
                }
            }

            return(result);
        }
Exemple #19
0
        public async Task List_PostDataSourceRequestAndLogSearchModel_ReturnJsonResult()
        {
            // Arrange
            var logService = Substitute.For <ILogService>();

            logService.GetLogs(Arg.Any <LogPagedDataRequest>()).Returns(_logs);

            var sut = new LogsController(logService);

            var request = new DataSourceRequest {
                Sorts = new List <SortDescriptor>()
            };
            var model = new LogSearchModel();

            // Act
            var jsonResult = (JsonResult)await sut.List(request, model);

            // Assert
            var dataSourceResult = (DataSourceResult)jsonResult.Data;
            var models           = (IEnumerable <LogModel>)dataSourceResult.Data;

            Assert.AreEqual(3, models.Count());
        }
Exemple #20
0
        private LogPagedDataRequest ParsePagedDataRequest(DataSourceRequest request, LogSearchModel model)
        {
            var dataRequest = new LogPagedDataRequest
            {
                Thread    = model.Thread,
                Username  = model.SelectedUsername,
                Level     = model.SelectedLevel,
                Message   = model.Message,
                Exception = model.Exception,
                PageIndex = request.Page - 1,
                PageSize  = request.PageSize
            };

            if (model.FromDate.HasValue)
            {
                dataRequest.FromDate = model.FromDate.Value;
            }

            if (model.ToDate.HasValue)
            {
                dataRequest.ToDate = model.ToDate.Value.ToEndOfDay();
            }

            SortDescriptor sort = request.Sorts.FirstOrDefault();

            if (sort != null)
            {
                LogSortField sortField;
                if (!Enum.TryParse(sort.Member, out sortField))
                {
                    sortField = LogSortField.Date;
                }
                dataRequest.SortField = sortField;
                dataRequest.SortOrder = sort.SortDirection == ListSortDirection.Ascending ? SortOrder.Ascending : SortOrder.Descending;
            }
            return(dataRequest);
        }
Exemple #21
0
 public async Task <PagedModel <SysOperationLogDto> > SearchOperationLogs(LogSearchModel searchModel)
 {
     return(await _logService.SearchOperationLogs(searchModel));
 }
Exemple #22
0
        public async Task <ActionResult> List([DataSourceRequest] DataSourceRequest request, LogSearchModel model)
        {
            var dataRequest = ParsePagedDataRequest(request, model);
            var entities    = await _logService.GetLogs(dataRequest);

            var models = entities.Select(x => x.ToModel()).ToList();
            var result = new DataSourceResult {
                Data = models.ToList(), Total = entities.TotalCount
            };

            return(Json(result));
        }