public virtual NippsModuleResponse LogSetLevel(NippsModuleRequest nippsModuleRequest) { if (nippsModuleRequest == null || nippsModuleRequest.NippsModules == null || nippsModuleRequest.NippsModules.Count == 0) { return new NippsModuleResponse { Result = Result.FAIL }; } NippsModule nippsModule = nippsModuleRequest.NippsModules[0]; string newLogLevel = Enum.GetName(typeof(NippsLogLevel), nippsModule.LogLevelId); foreach (LoggingRule rule in NLog.LogManager.Configuration.LoggingRules) { //first disable all rule.DisableLoggingForLevel(LogLevel.Trace); rule.DisableLoggingForLevel(LogLevel.Debug); rule.DisableLoggingForLevel(LogLevel.Info); rule.DisableLoggingForLevel(LogLevel.Warn); rule.DisableLoggingForLevel(LogLevel.Error); rule.DisableLoggingForLevel(LogLevel.Fatal); //then enable the new one rule.EnableLoggingForLevel(LogLevel.FromString(newLogLevel)); } NLog.LogManager.ReconfigExistingLoggers(); return new NippsModuleResponse { Result = Result.OK }; }
public NippsModuleResponse List(NippsModuleRequest nippsModuleRequest) { //this operation returns only parent modules, not childs. NippsModuleResponse response = new NippsModuleResponse(); response.ResultMessages = new List<string>(); if (nippsModuleRequest == null) nippsModuleRequest = new NippsModuleRequest { PageNo = 1, PageSize = 1000, NippsModules = new List<NippsModule> { new NippsModule { ParentId = 0 } } }; if (nippsModuleRequest.PageNo < 1) nippsModuleRequest.PageNo = 1; if (nippsModuleRequest.PageSize == 0) nippsModuleRequest.PageSize = 1000; if (nippsModuleRequest.NippsModules == null || nippsModuleRequest.NippsModules.Count == 0) nippsModuleRequest.NippsModules = new List<NippsModule> { new NippsModule { ParentId = 0 } }; try { using (ILifetimeScope scope = NippsIoCHelper.IoCContainer.BeginLifetimeScope()) { IGenericLogicV2<NippsModule> logModuleLogic = scope.Resolve<IGenericLogicV2<NippsModule>>(); logModuleLogic.PageSize = nippsModuleRequest.PageSize; try { response.NippsModules = logModuleLogic.List(nippsModuleRequest.NippsModules[0], nippsModuleRequest.PageNo); response.Result = Result.OK; } catch (NoDataFoundException ex) { response.Result = Result.FAIL; response.ResultMessages.Add(ex.Message); } catch (Exception ex) { response.Result = Result.FAIL; response.ResultMessages.Add(ex.ToString()); } } } catch (Exception ex) { response.Result = Result.FAIL; response.ResultMessages.Add(ex.Message); mLogger.Error(ex); } return response; }
public ActionResult StatusList() { try { List<NippsParameter> nippsHosts = NippsSiteHelper.ListNippsHost(); NippsModuleRequest nippsModuleRequest = new NippsModuleRequest(); nippsModuleRequest.NippsModules = new List<NippsModule>(); foreach (NippsParameter nippsHost in nippsHosts) foreach (string value in nippsHost.ParameterValue.Split('|')) NippsSiteHelper.ListNippsSite(value) .ForEach(delegate(NippsSite nippsSite) { nippsSite.NippsApplications .ForEach(delegate(NippsApplication nippsApplication) { if (nippsApplication.Path.StartsWith("/Netas.Nipps.Service.")) nippsModuleRequest.NippsModules.Add( new NippsModule { ModuleName = value + ">" + nippsSite.Name + ">" + nippsApplication.Path, ParentId = 0 }); }); }); NippsModuleResponse nippsModuleResponse; if (nippsModuleRequest.NippsModules.Count > 0) try { RestPostNippsModuleRequest("Add", nippsModuleRequest); } catch (Exception ex) { } nippsModuleResponse = RestPostNippsModuleRequest("List", new NippsModuleRequest()); ViewBag.ResultList = nippsModuleResponse.NippsModules; SetViewBagResult(nippsModuleResponse, ViewBag); } catch (Exception ex) { Logger.Error(ex.ToString()); SetViewBagResult(new NippsModuleResponse { Result = Result.FAIL, ResultMessages = new List<string> { ex.ToString() } }, ViewBag); } return View(); }
private NippsModuleResponse RestPostNippsModuleRequest(string actionUri, NippsModuleRequest nippsModuleRequest) { string svcUri = CommonHelper.LogManagerServiceUrl + "NippsModuleService/" + actionUri; NippsModuleResponse nippsModuleResponse = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(svcUri, nippsModuleRequest); if (nippsModuleResponse.Result == Result.OK) return nippsModuleResponse; throw new Exception(nippsModuleResponse.ResultMessages[0]); }
private List<NippsModule> ListSMModules() { NippsModuleRequest request = new NippsModuleRequest { NippsModules = new List<NippsModule> { new NippsModule { ParentId = 1 } } }; NippsModuleResponse response = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>( CommonHelper.LogManagerServiceUrl + "NippsModuleService/List" , request); return response.NippsModules; }
private static void UpdateNippsModule(NippsModule nippsModule, dynamic ViewBag) { string uri = CommonHelper.LogManagerServiceUrl + "NippsModuleService/Update"; NippsModuleRequest moduleUpdateRequest = new NippsModuleRequest { NippsModules = new List<NippsModule> { nippsModule } }; NippsModuleResponse moduleUpdateResponse = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(uri, moduleUpdateRequest); ViewBag.Name = Resources.Global.LogParametersChange; SetViewBagResult(moduleUpdateResponse, ViewBag); }
private static void SetLogLevel(NippsModule nippsModule, ModuleNameParser mnp, dynamic ViewBag) { string uri = NippsSiteHelper.ServiceLogUrl(mnp) + "LogSetLevel"; NippsModuleRequest logRequest = new NippsModuleRequest { NippsModules = new List<NippsModule> { nippsModule } }; NippsModuleResponse logResponse = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(uri, logRequest); ViewBag.Name = Resources.Global.LogLevelChange; SetViewBagResult(logResponse, ViewBag); }
public NippsModuleResponse GetByName(NippsModuleRequest nippsModuleRequest) { NippsModuleResponse response = new NippsModuleResponse(); response.ResultMessages = new List<string>(); if (nippsModuleRequest == null || nippsModuleRequest.NippsModules == null || nippsModuleRequest.NippsModules.Count() == 0 || string.IsNullOrEmpty(nippsModuleRequest.NippsModules[0].ModuleName) ) { response.Result = Result.FAIL; response.ResultMessages.Add("NippsModules can not be null."); return response; } try { using (ILifetimeScope scope = NippsIoCHelper.IoCContainer.BeginLifetimeScope()) { IGenericLogicV2<NippsModule> logModuleLogic = scope.Resolve<IGenericLogicV2<NippsModule>>(); bool succeededOne = false; response.NippsModules = new List<NippsModule>(); response.Result = Result.OK; foreach (NippsModule logModule in nippsModuleRequest.NippsModules) { try { response.NippsModules.Add(logModuleLogic.GetByName(logModule.ModuleName)); succeededOne = true; } catch (Exception ex) { if (succeededOne) response.Result = Result.SUCCESSWITHWARN; else response.Result = Result.FAIL; response.ResultMessages.Add(ex.ToString()); } } } } catch (Exception ex) { response.Result = Result.FAIL; response.ResultMessages.Add(ex.Message); mLogger.Error(ex); } return response; }
public override NippsModuleResponse LogSetLevel(NippsModuleRequest nippsModuleRequest) { NippsModuleResponse nippsModuleResponse = Update(nippsModuleRequest); if (nippsModuleResponse.Result == Result.OK) { LogLevel newLogLevel = nippsModuleRequest.NippsModules[0].LogLevelId == NippsLogLevel.Trace ? LogLevel.Trace : nippsModuleRequest.NippsModules[0].LogLevelId == NippsLogLevel.Debug ? LogLevel.Debug : nippsModuleRequest.NippsModules[0].LogLevelId == NippsLogLevel.Info ? LogLevel.Info : nippsModuleRequest.NippsModules[0].LogLevelId == NippsLogLevel.Warn ? LogLevel.Warn : nippsModuleRequest.NippsModules[0].LogLevelId == NippsLogLevel.Error ? LogLevel.Error : nippsModuleRequest.NippsModules[0].LogLevelId == NippsLogLevel.Fatal ? LogLevel.Fatal : LogLevel.Off; foreach (LoggingRule rule in NLog.LogManager.Configuration.LoggingRules) { rule.DisableLoggingForLevel(LogLevel.Trace); rule.DisableLoggingForLevel(LogLevel.Debug); rule.DisableLoggingForLevel(LogLevel.Info); rule.DisableLoggingForLevel(LogLevel.Warn); rule.DisableLoggingForLevel(LogLevel.Error); rule.DisableLoggingForLevel(LogLevel.Fatal); if (newLogLevel != LogLevel.Off) rule.EnableLoggingForLevel(newLogLevel); } NLog.LogManager.ReconfigExistingLoggers(); } return nippsModuleResponse; }
bool RemoveNippsModule(NippsModule nippsModule) { try { string svcUrl = CommonHelper.LogManagerServiceUrl + "NippsModuleService/Remove"; NippsModuleRequest moduleRequest = new NippsModuleRequest { NippsModules = new List<NippsModule> { nippsModule } }; NippsModuleResponse moduleResponse = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(svcUrl, moduleRequest); if (moduleResponse.Result == Result.OK) return true; Logger.Error("{0}: {1}", nippsModule, moduleResponse.ResultMessages[0]); } catch (Exception ex) { Logger.Error("{0}: {1}", nippsModule, ex.ToString()); } return false; }
NippsModule GetNippsModule(Models.Nipps nipps) { try { string moduleName = nipps.HostName + ">" + nipps.SiteName + ">" + nipps.ApplicationName; string svcUrl = CommonHelper.LogManagerServiceUrl + "NippsModuleService/GetByName"; NippsModuleRequest moduleRequest = new NippsModuleRequest { NippsModules = new List<NippsModule> { new NippsModule { ModuleName = moduleName } } }; NippsModuleResponse moduleResponse = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(svcUrl, moduleRequest); if (moduleResponse.Result == Result.OK) return moduleResponse.NippsModules[0]; Logger.Error("{0}: {1}", nipps, moduleResponse.ResultMessages[0]); } catch (Exception ex) { Logger.Error("{0}: {1}", nipps, ex.ToString()); } return null; }
public static List<NippsModule> ListNippsModule() { string logServiceUrl = CommonHelper.LogManagerServiceUrl + "NippsModuleService/List"; NippsModuleRequest request = new NippsModuleRequest { PageNo = 1, PageSize = 1000 }; NippsModuleResponse response = RestHelper.RestPostObject<NippsModuleResponse, NippsModuleRequest>(logServiceUrl, request); if (response.Result == Result.OK) return response.NippsModules; foreach (string em in response.ResultMessages) NLog.LogManager.GetCurrentClassLogger().Error(em); return new List<NippsModule>(); }