Beispiel #1
0
		/// <summary>
		/// 加载配置
		/// </summary>
		/// <param name="config"></param>
		/// <remarks>
		/// 只能在启动时调用
		/// </remarks>
		/// <exception cref="InvalidOperationException">配置已经被指定</exception>
		public void LoadConfig(LoggerConfig config)
		{
			if (_config != null)
				throw new InvalidOperationException("配置已经被指定.");

			_config = config;
			Name = _config.Name;
			NameSpace = _config.Namespace;

			if (_targets.Count != 0) 
				return;

			foreach (var target in _config.Targets)
				_targets.Add(target);
		}
Beispiel #2
0
        //解析loggers节点
        private void ParseLoggers(XmlNodeList nodes)
        {
            foreach (XmlNode node in nodes)
            {
                if (node is XmlComment) continue;

                var config = new LoggerConfig
                {
                    ChildConfig = node.ChildNodes,
                    Namespace = GetAttribute(node, "namespace","*"),//若namespace属性没配置,则默认为“*”,表示该Logger可以在任意地方写日志
                    Name = GetAttribute(node, "name", true)
                };

                string[] names = GetAttribute(node, "targets", true).Split(',');
                foreach (string name in names)
                    config.TargetNames.Add(name.Trim());

                try
                {
                    string minLevel = GetAttribute(node, "minLevel", false);
                    if (!string.IsNullOrEmpty(minLevel))
                        config.MinLevel = (LogLevel)Enum.Parse(typeof(LogLevel), minLevel);
                    else
                        config.MinLevel = LogLevel.Trace;
                }
                catch (Exception ex)
                {
                    throw new ConfigurationErrorsException(string.Format("解析minLevel属性时出错,错误信息:{0}", ex.Message));
                }

                _Loggers.Add(config);
            }
        }
Beispiel #3
0
 	/// <summary>
 	/// 加载配置
 	/// </summary>
 	public void LoadConfig(LoggerConfig config)
 	{
 	}
Beispiel #4
0
 /// <summary>
 /// 加载配置
 /// </summary>
 public void LoadConfig(LoggerConfig config)
 {
 }