Exemplo n.º 1
0
 /// <summary>
 /// Adding a logger
 /// </summary>
 /// <param name="Name">Namespace name of teh logger to be found</param>
 /// <param name="appender">Appender</param>
 /// <param name="level">Logging level
 ///Log level priority in descending order:
 ///FATAL = 1 show  log -> FATAL
 ///ERROR = 2 show  log -> FATAL ERROR
 ///WARN =  3 show  log -> FATAL ERROR WARN
 ///INFO =  4 show  log -> FATAL ERROR WARN INFO
 ///DEBUG = 5 show  log -> FATAL ERROR WARN INFO DEBUG
 /// </param>
 public void AddLogger(string Name, IAppender appender, Level level)
 {
     try
     {
         _HierarchyLogger.Configured = false;
         Logger L = _HierarchyLogger.GetLogger(Name) as Logger;
         _Loggers.Add(L);
         L.Level = level;
         L.AddAppender(appender);
         _HierarchyLogger.Configured = true;
         _HierarchyLogger.RaiseConfigurationChanged(EventArgs.Empty);
     }
     catch (Exception e)
     {
         Console.WriteLine("appender error : " + e);
     }
 }
 private void CreateDefaultMemoryAppender()
 {
     _memoryAppender      = new RollingMemoryAppender();
     _memoryAppender.Name = "DeveloperToolsLogViewer";
     _memoryAppender.ActivateOptions();
     log4net.Repository.Hierarchy.Hierarchy repository = LogManager.GetRepository() as Hierarchy;
     repository.Root.AddAppender(_memoryAppender);
     repository.Root.Level = Level.All;
     repository.Configured = true;
     repository.RaiseConfigurationChanged(EventArgs.Empty);
 }
Exemplo n.º 3
0
        static void PrepareLoggerLevel(ILoggerRepository repository, string domain, string level)
        {
            repository.Threshold = repository.LevelMap[level];
            log4net.Repository.Hierarchy.Hierarchy hier = (log4net.Repository.Hierarchy.Hierarchy)repository;
            log4net.Core.ILogger[] loggers = hier.GetCurrentLoggers();
            foreach (log4net.Core.ILogger logger in loggers)
            {
                Console.WriteLine(logger.Name);

                ((log4net.Repository.Hierarchy.Logger)logger).Level = hier.LevelMap[level];

                if (Environment.UserInteractive)
                {
                    ((log4net.Repository.Hierarchy.Logger)logger).RemoveAllAppenders();
                    ColoredConsoleAppender appender = CreateColoredConsoleAppender(domain);
                    ((log4net.Repository.Hierarchy.Logger)logger).AddAppender(appender);
                    (appender.Layout as SyslogLayout).ActivateOptions();
                    appender.ActivateOptions();
                }
            }
            hier.RaiseConfigurationChanged(EventArgs.Empty);
        }