Пример #1
0
		/// <summary>
		/// 获取日志记录器(为当前类找出匹配的日志记录器)
		/// </summary>
		public ILogger GetCurrentClassLogger()
		{
			var frame = new StackFrame(2);  //调用日志记录器的类所在的堆栈帧
			Type classType = frame.GetMethod().ReflectedType;

			// 查找配置中所有匹配的日志记录器
			IList<ILogger> loggers = FindLoggers(classType);
			if (loggers.Count == 0)
			{
				return LogManager.NullLogger;
			}
			if (loggers.Count == 1)
				return loggers[0];

			MultiLogger logger = new MultiLogger(loggers);
			LogLevel minLevel = LogLevel.Fatal;
			foreach (var logger1 in loggers)
			{
				if (logger1.MinLevel < minLevel)
					minLevel = logger1.MinLevel;
			}

			logger.LoadConfig(new LoggerConfig{MinLevel = minLevel, Name = "MultiLogger"});
			return logger;
		}
Пример #2
0
        /// <summary>
        /// 获取日志记录器(为当前类找出匹配的日志记录器)
        /// </summary>
        public ILogger GetCurrentClassLogger()
        {
            var  frame     = new StackFrame(2);         //调用日志记录器的类所在的堆栈帧
            Type classType = frame.GetMethod().ReflectedType;

            // 查找配置中所有匹配的日志记录器
            IList <ILogger> loggers = FindLoggers(classType);

            if (loggers.Count == 0)
            {
                return(LogManager.NullLogger);
            }
            if (loggers.Count == 1)
            {
                return(loggers[0]);
            }

            MultiLogger logger   = new MultiLogger(loggers);
            LogLevel    minLevel = LogLevel.Fatal;

            foreach (var logger1 in loggers)
            {
                if (logger1.MinLevel < minLevel)
                {
                    minLevel = logger1.MinLevel;
                }
            }

            logger.LoadConfig(new LoggerConfig {
                MinLevel = minLevel, Name = "MultiLogger"
            });
            return(logger);
        }