Beispiel #1
0
 /// <summary>
 /// 加载log4net配置文件
 /// </summary>
 public static void LoadConfig(LogConfigInfo info)
 {
     config = info;
     StartMonitor();
 }
Beispiel #2
0
        /// <summary>
        /// 获取配置文件信息
        /// </summary>
        private bool GetConfigInfo(ref string errorMsg)
        {
            System.Collections.Generic.List <string> allkeyList = null;
            if (ConfigurationManager.AppSettings.AllKeys.Length > 0)
            {
                allkeyList = new System.Collections.Generic.List <string>(ConfigurationManager.AppSettings.AllKeys);
            }
            //判断配置文件信息[先检查Http前缀(触角服务及客户系统接入)]
            if (allkeyList == null || !allkeyList.Contains("HttpPrdfixService") || !allkeyList.Contains("HttpPrdfixCustoms") ||
                string.IsNullOrEmpty(ConfigurationManager.AppSettings["HttpPrdfixService"]) ||
                string.IsNullOrEmpty(ConfigurationManager.AppSettings["HttpPrdfixCustoms"]))
            {
                errorMsg += "配置文件错误!";
                return(false);
            }
            var antsdkconfig = new SDK.AntSdk.AntModels.AntSdkConfig
            {
                AntServiceHttpPrdfix = ConfigurationManager.AppSettings["HttpPrdfixService"],
                CustomersHttpPrdfix  = ConfigurationManager.AppSettings["HttpPrdfixCustoms"],
                AppVersion           = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
            };
            //日志配置
            var logconfigInfo = new LogConfigInfo();
            var logenabled    = false;

            bool.TryParse(ConfigurationManager.AppSettings["DebugLogEnable"], out logenabled);
            if (logenabled)
            {
                antsdkconfig.AntSdkLogMode |= SDK.AntSdk.AntSdkLogLevel.DebugLogEnable;
            }
            logconfigInfo.DebugLogEnable = logenabled;
            logenabled = false;
            bool.TryParse(ConfigurationManager.AppSettings["InfoLogEnable"], out logenabled);
            if (logenabled)
            {
                antsdkconfig.AntSdkLogMode |= SDK.AntSdk.AntSdkLogLevel.InfoLogEnable;
            }
            logconfigInfo.InfoLogEnable = logenabled;
            logenabled = false;
            bool.TryParse(ConfigurationManager.AppSettings["WarnLogEnable"], out logenabled);
            if (logenabled)
            {
                antsdkconfig.AntSdkLogMode |= SDK.AntSdk.AntSdkLogLevel.WarnLogEnable;
            }
            logconfigInfo.WarnLogEnable = logenabled;
            logenabled = false;
            bool.TryParse(ConfigurationManager.AppSettings["ErrorLogEnable"], out logenabled);
            if (logenabled)
            {
                antsdkconfig.AntSdkLogMode |= SDK.AntSdk.AntSdkLogLevel.ErrorLogEnable;
            }
            logconfigInfo.ErrorLogEnable = logenabled;
            logenabled = false;
            bool.TryParse(ConfigurationManager.AppSettings["FatalLogEnable"], out logenabled);
            if (logenabled)
            {
                antsdkconfig.AntSdkLogMode |= SDK.AntSdk.AntSdkLogLevel.FatalLogEnable;
            }
            logconfigInfo.FatalLogEnable = logenabled;
            //启动触角SDK
            var temperrorMsg = string.Empty;

            if (!SDK.AntSdk.AntSdkService.StartAntSdk(antsdkconfig, ref temperrorMsg))
            {
                errorMsg += $"启动触角SDK错误{temperrorMsg}";
                return(false);
            }

            LogHelper.LoadConfig(logconfigInfo);
            //返回
            return(true);
        }