Beispiel #1
0
        /// <summary>
        /// Sets logging level for all current loggers to the level provided in arguments.
        /// Note: use it only when you need more control on logging, e.g. in unit tests. Otherwise use configuration files.
        /// </summary>
        /// <param name="level"></param>
        public static void SetLoggingLevel(log4net.Core.Level level)
        {
            var repositories = log4net.LogManager.GetAllRepositories();

            //Configure all loggers to be at the debug level.
            foreach (var repository in repositories)
            {
                repository.Threshold = repository.LevelMap[level.ToString()];
                var hierarchy = (log4net.Repository.Hierarchy.Hierarchy)repository;
                var loggers = hierarchy.GetCurrentLoggers();
                foreach (var logger in loggers)
                {
                    ((log4net.Repository.Hierarchy.Logger)logger).Level = hierarchy.LevelMap[level.ToString()];
                }
            }

            //Configure the root logger.
            var h = (log4net.Repository.Hierarchy.Hierarchy)log4net.LogManager.GetRepository();
            var rootLogger = h.Root;
            rootLogger.Level = h.LevelMap[level.ToString()];
        }
		public void ToStringOnObjectIfNoMessageIsProvided()
		{
			var layout = new LogMessageLayout();

			var message = new { Test = 1, Test2 = 2 };

			var loggingEvent = GetLogginEvent(message);

			var result = GetMessage(layout, loggingEvent);

			Assert.AreEqual(result["Test"], message.Test.ToString());
			Assert.AreEqual(result["Test2"], message.Test2.ToString());
			Assert.AreEqual(result.Message, message.ToString());
		}