public async Task <IResponse <Dictionary <string, int> > > GetLossCountLastDaysAsync(int dayCount = 10) { var result = new Response <Dictionary <string, int> >(); try { var cache = (Response <Dictionary <string, int> >)_cacheProvider.Get(LossCountLastDaysCacheKey()); if (cache != null) { return(cache); } result.Result = await _appUow.LossRepo.GetLossCountLastDaysAsync(dayCount); if (result.Result.Count() == 0) { return new Response <Dictionary <string, int> > { Message = ServiceMessage.RecordNotExist } } ; result.IsSuccessful = true; result.Message = ServiceMessage.Success; _cacheProvider.Add(LossCountLastDaysCacheKey(), result, DateTimeOffset.Now.AddMinutes(30)); return(result); } catch (Exception e) { FileLoger.Error(e); return(result); } }
/// <summary> /// Returns a preconfigured instance of serilog logger. /// Audit log messages will be inserted into a local sqlite database. /// Error messages on the other hand will be added on top of a rolling file log. /// Graylog messages will be sent to a Graylog server (if one exists). /// </summary> /// <param name="niasMessageAudit"></param> /// <returns></returns> public ILogger GetLogger(SerilogLogTypesEnum niasMessageAudit) { var rollingLogLogPath = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogRollingLogLogPath"); var rollingLogLogFileName = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogRollingLogLogFileName"); var rollingLogLogTemplate = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogRollingLogLogTemplate"); var SqliteErrorLogPath = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogSqlLiteErrorLogPath"); var SqliteErrorLogFileName = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogSqlLiteErrorLogFileName"); var SqliteAuditLogPath = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogSqlLiteAuditLogPath"); var SqliteAuditLogFileName = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogSqlLiteAuditLogFileName"); var SqlitePerformanceLogPath = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogSqlLitePerformanceLogPath"); var SqlitePerformanceLogFileName = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogSqlLitePerformanceLogFileName"); var shouldUseGraylog = _configurationRepository.GetConfigurationValueOrDefaultAndNotifyIfPropertyNotFound("SerilogUsesGraylog", false); var graylogIP = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>( "SerilogGraylogAdress"); var graylogPort = _configurationRepository.GetConfigurationValueAndNotifyIfPropertyNotFound <string>("SerilogGraylogPort"); switch (niasMessageAudit) { case SerilogLogTypesEnum.PerformanceLog: if (!string.IsNullOrEmpty(SqliteAuditLogPath) && !string.IsNullOrEmpty(SqliteAuditLogFileName)) { _logConfiguration = new LoggerConfiguration().WriteTo.SQLitePerformanceAudit( $"{SqlitePerformanceLogPath}{SqlitePerformanceLogFileName}"); if (_memoryCacheProvider.Get <ILogger>("PerformanceLog") == null) { _internalSerilogLogger = _logConfiguration.CreateLogger(); _memoryCacheProvider.Save(_internalSerilogLogger, "PerformanceLog"); } else { return(_memoryCacheProvider.Get <ILogger>("PerformanceLog")); } } break; case SerilogLogTypesEnum.Graylog: if (shouldUseGraylog) { if (!string.IsNullOrEmpty(graylogIP) && !string.IsNullOrEmpty(graylogPort)) { _logConfiguration = new LoggerConfiguration().WriteTo.Graylog(new GraylogSinkOptions { HostnameOrAdress = graylogIP, Port = Convert.ToInt32(graylogPort) }); if (_memoryCacheProvider.Get <ILogger>("GraylogLog") == null) { _internalSerilogLogger = _logConfiguration.CreateLogger(); _memoryCacheProvider.Save(_internalSerilogLogger, "GraylogLog"); } else { return(_memoryCacheProvider.Get <ILogger>("GraylogLog")); } } else { _internalSerilogLogger.Error(Err_Graylog_Settings_Invalid); } } break; case SerilogLogTypesEnum.ErrorRollingLog: if (!string.IsNullOrEmpty(rollingLogLogPath) && !string.IsNullOrEmpty(rollingLogLogFileName)) { _logConfiguration = new LoggerConfiguration().WriteTo.RollingFile( rollingLogLogPath + rollingLogLogFileName, outputTemplate: rollingLogLogTemplate); _internalSerilogLogger = _logConfiguration.CreateLogger(); if (_memoryCacheProvider.Get <ILogger>("ErrorLogInFile") == null) { _memoryCacheProvider.Save(_internalSerilogLogger, "ErrorLogInFile"); } else { return(_memoryCacheProvider.Get <ILogger>("ErrorLogInFile")); } } break; } return(_internalSerilogLogger); }
public MenuModel GetAvailableActions(Guid userId, List <MenuSPModel> spResult = null, string urlPrefix = "") { var userMenu = (MenuModel)_cache.Get(GlobalVariables.CacheSettings.MenuModelCacheKey(userId)); if (userMenu != null) { return(userMenu); } userMenu = new MenuModel(); if (spResult == null) { spResult = _dashboardMenuSp.GetUserMenu(userId).ToList(); } #region Find Default View foreach (var menuItem in spResult) { if (menuItem.IsAction && menuItem.IsDefault) { userMenu.DefaultUserAction = new UserAction { Action = menuItem.ActionName, Controller = menuItem.ControllerName }; break; } var actions = menuItem.ActionsList; if (actions.Any(x => x.IsDefault)) { userMenu.DefaultUserAction = new UserAction { Action = actions.FirstOrDefault(x => x.IsDefault).ActionName, Controller = actions.FirstOrDefault(x => x.IsDefault).ControllerName }; break; } } if (userMenu.DefaultUserAction == null || userMenu.DefaultUserAction.Controller == null) { return(null); } #endregion var userActions = new List <UserAction>(); foreach (var item in spResult) { if (item.IsAction) { userActions.Add(new UserAction { Controller = item.ControllerName.ToLower(), Action = item.ActionName.ToLower(), RoleId = item.RoleId, RoleNameFa = item.RoleNameFa }); } if (item.ActionsList != null) { foreach (var child in item.ActionsList) { userActions.Add(new UserAction { Controller = child.ControllerName.ToLower(), Action = child.ActionName.ToLower(), RoleId = child.RoleId, RoleNameFa = child.RoleNameFa }); } } } userActions = userActions.Distinct().ToList(); userMenu.Menu = GetAvailableMenu(spResult, urlPrefix); userMenu.ActionList = userActions; _cache.Add(GlobalVariables.CacheSettings.MenuModelCacheKey(userId), userMenu, DateTime.Now.AddMinutes(30)); return(userMenu); }