Exemple #1
0
        public override void Initialize(XAccessor x)
        {
            _teardown = x.GetValue <bool>(TEARDOWN_ATTR) ?? false;
            var xParams = x.NavigateToList(PARAM);

            foreach (var xParam in xParams)
            {
                string name = xParam.GetStringValue(NAME_ATTR);
                string val  = xParam.GetStringValue(VALUE_ATTR);
                if (string.IsNullOrEmpty(name))
                {
                    ExceptionHelper.ThrowPolicyInitNullError(this.GetType(), NAME_ATTR);
                }
                _injectionHints.Add(name, val);
            }
            string strFactoryType = x.GetStringValue(CLASS);

            if (string.IsNullOrEmpty(strFactoryType))
            {
                ExceptionHelper.ThrowPolicyInitNullError(this.GetType(), CLASS);
            }
            _factoryType = Reflector.LoadType(strFactoryType);
            _methodName  = x.GetStringValue(METHOD);
            if (string.IsNullOrEmpty(_methodName))
            {
                ExceptionHelper.ThrowPolicyInitNullError(this.GetType(), METHOD);
            }
        }
Exemple #2
0
        private void Initialize()
        {
            _layout = Reflector.LoadInstance <ILayout>(_x.GetStringValue(LAYOUT));
            _writer = Reflector.LoadInstance <IWriter>(_x.GetStringValue(WRITER));

            var logs = _x.NavigateToList(LOG);

            foreach (XAccessor log in logs)
            {
                string name = log.GetStringValue(NAME_ATTR);
                if (string.IsNullOrWhiteSpace(name))
                {
                    ExceptionHelper.ThrowConfigItemNull("log name");
                }
                LogLevel?level = log.GetEnumValue <LogLevel>(LEVEL_ATTR);
                if (!level.HasValue)
                {
                    ExceptionHelper.ThrowConfigItemNull("log level");
                }
                _cache.Add(name, level.Value);
            }

            _cache.SetDefaultIfNotExist();
        }