示例#1
0
        public void Load(IProperties sourceProperties)
        {
            foreach (String key in sourceProperties.CollectAllPropertyKeys())
            {
                String value = sourceProperties.GetString(key);

                this[key] = value;
            }
        }
示例#2
0
        public static void ConfigureLogger(String loggerName, IConfigurableLogger logger, IProperties appProps)
        {
            HashSet <String> allPropertiesSet = new HashSet <String>();

            appProps.CollectAllPropertyKeys(allPropertiesSet);
            // highest precision found
            int logLevelHPF = 0, logConsoleHPF = 0, logSourceHPF = 0;

            foreach (String key in allPropertiesSet)
            {
                Match match = logLevelRegex.Match(key);
                if (!match.Success)
                {
                    continue;
                }
                String type   = match.Groups[1].Value;
                String target = match.Groups[2].Value;
                if (target != null && !loggerName.StartsWith(target))
                {
                    continue;
                }
                if (target == null)
                {
                    target = "";
                }
                if (logLevelPropertyName.Equals(type))
                {
                    if (target.Length < logLevelHPF)
                    {
                        continue;
                    }
                    logLevelHPF = target.Length;
                    String valueString = appProps.GetString(key).ToLower();
                    if ("debug".Equals(valueString))
                    {
                        logger.DebugEnabled = true;
                        logger.InfoEnabled  = true;
                        logger.WarnEnabled  = true;
                        logger.ErrorEnabled = true;
                    }
                    else if ("info".Equals(valueString))
                    {
                        logger.DebugEnabled = false;
                        logger.InfoEnabled  = true;
                        logger.WarnEnabled  = true;
                        logger.ErrorEnabled = true;
                    }
                    else if ("warn".Equals(valueString))
                    {
                        logger.DebugEnabled = false;
                        logger.InfoEnabled  = false;
                        logger.WarnEnabled  = true;
                        logger.ErrorEnabled = true;
                    }
                    else if ("error".Equals(valueString))
                    {
                        logger.DebugEnabled = false;
                        logger.InfoEnabled  = false;
                        logger.WarnEnabled  = false;
                        logger.ErrorEnabled = true;
                    }
                }
                else if (logConsolePropertyName.Equals(type))
                {
                    if (target.Length < logConsoleHPF)
                    {
                        continue;
                    }
                    logConsoleHPF = target.Length;
                    String valueString = appProps.GetString(key).ToLower();
                    logger.LogToConsole = Boolean.Parse(valueString);
                }
                else if (logSourcePropertyName.Equals(type))
                {
                    if (target.Length < logSourceHPF)
                    {
                        continue;
                    }
                    logSourceHPF = target.Length;
                    String valueString = appProps.GetString(key);
                    logger.LogSourceLevel = (LogSourceLevel)Enum.Parse(typeof(LogSourceLevel), valueString, true);
                }
                else
                {
                    throw new Exception("Property: " + key + " not supported");
                }
            }
            logger.PostProcess(appProps);
        }