/// <summary> /// /// </summary> private void ConfigureLogger() { var repos = LogManager.GetAllRepositories(); ILoggerRepository repo = null; foreach (var r in repos) { if (r.Name == Run.RunName) { repo = r; } } if (repo == null) { repo = LogManager.CreateRepository(Run.RunName); } var logger = repo.GetLogger(Run.RunName); var ilogger = repo.GetLogger(Run.RunName); var appender = new log4net.Appender.RollingFileAppender(); appender.Name = "RollingFileAppender"; appender.File = Path.Combine(Run.RunDirectory, "XTMF.Console.log"); appender.StaticLogFileName = true; appender.AppendToFile = false; appender.RollingStyle = log4net.Appender.RollingFileAppender.RollingMode.Once; appender.MaxSizeRollBackups = 10; appender.MaximumFileSize = "10MB"; appender.PreserveLogFileNameExtension = true; var layout = new log4net.Layout.PatternLayout() { ConversionPattern = "%date %-5level %logger - %message%newline" }; appender.Layout = layout; layout.ActivateOptions(); _consoleAppener = new ConsoleOutputAppender() { Layout = layout }; //Let log4net configure itself based on the values provided appender.ActivateOptions(); log4net.Config.BasicConfigurator.Configure(repo, appender, _consoleAppener); iLog = LogManager.GetLogger(Run.RunName, Run.RunName); }
public ILogger CreateLogger(string categoryName) { var logger = _loggerRepository.GetLogger(categoryName); var impl = new LogImpl(logger); return(new Log4NetLogger(impl)); }
/// <summary> /// Configures the <see cref="FileLogger"/> logger adding the appenders /// to the root repository. /// </summary> public void Configure() { // create a new logger into the repository of the current assembly. ILoggerRepository root_repository = LogManager.GetRepository(Assembly.GetExecutingAssembly()); Logger nohros_console_logger = root_repository.GetLogger("NohrosConsoleLogger") as Logger; // create the layout and appender for on error messages. PatternLayout layout = new PatternLayout(); layout.ConversionPattern = layout_pattern_; layout.ActivateOptions(); // create the appender ConsoleAppender appender = new ConsoleAppender(); appender.Name = "NohrosCommonConsoleAppender"; appender.Layout = layout; appender.Target = "Console.Out"; appender.Threshold = Level.All; appender.ActivateOptions(); nohros_console_logger.Parent.AddAppender(appender); root_repository.Configured = true; logger = LogManager.GetLogger("NohrosConsoleLogger"); }
/// <summary> /// Configures the <see cref="FileLogger"/> logger adding the appenders to /// the root repository. /// </summary> /// <remarks></remarks> public void Configure() { // create a new logger into the repository of the current assembly. ILoggerRepository root_repository = LogManager.GetRepository(Assembly.GetExecutingAssembly()); Logger nohros_file_logger = root_repository.GetLogger("NohrosFileAppender") as Logger; // create the layout and appender for log messages PatternLayout layout = new PatternLayout(); layout.ConversionPattern = layout_pattern_; layout.ActivateOptions(); FileAppender appender = new FileAppender(); appender.Name = "NohrosCommonFileAppender"; appender.File = log_file_path_; appender.AppendToFile = true; appender.Layout = layout; appender.Threshold = Level.All; appender.ActivateOptions(); // add the appender to the root repository nohros_file_logger.Parent.AddAppender(appender); root_repository.Configured = true; logger = LogManager.GetLogger("NohrosFileLogger"); }
public Log GetLogger(Type type) { LogImpl log; if (map.TryGetValue(type.FullName, out log)) { return(log); } else { ILogger logger = repository.GetLogger(type.FullName); log = new LogImpl(logger); map[type.FullName] = log; } return(log); }
/// <summary> /// initializes the log system using the logfile argument /// </summary> private void internalInit(String logfile) { // create a new logging domain ILoggerRepository domain = null; try { domain = log4net.LogManager.GetLoggerRepository(System.Reflection.Assembly.GetExecutingAssembly().FullName); } catch (LogException) { // Do nothing, this is expected if the domain has not been created } // create and initialize the domain if it does not exist if (domain == null) { domain = log4net.LogManager.CreateDomain(System.Reflection.Assembly.GetExecutingAssembly().FullName); // create an appender for the domain RollingFileAppender appender = new RollingFileAppender(); appender.Layout = new PatternLayout("%d - %m%n"); appender.File = logfile; appender.AppendToFile = true; appender.MaxSizeRollBackups = 1; appender.MaximumFileSize = "100000"; appender.ActivateOptions(); // initialize/configure the domain log4net.Config.BasicConfigurator.Configure(domain, appender); } // create the category Object o = domain.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); if (o is ILog) { this.logger = (ILog)domain.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.FullName); } else { throw new System.Exception("got unexpected logger type: " + o.GetType().ToString()); } }
public ILogger CreateLogger(string categoryName) { Log4NetLogger CreateLog4NetLogger(string category) { var logger = _loggerRepository.GetLogger(category); var impl = new LogImpl(logger); return(new Log4NetLogger(impl)); } return(_loggerCache.GetOrAdd(categoryName, CreateLog4NetLogger)); }
/// <summary> /// Configures the <see cref="FileLogger"/> logger adding the appenders /// to the root repository. /// </summary> public void Configure() { // create a new logger into the repository of the current assembly. ILoggerRepository root_repository = LogManager.GetRepository(Assembly.GetExecutingAssembly()); Logger nohros_console_logger = root_repository.GetLogger("NohrosConsoleLogger") as Logger; // create the layout and appender for on error messages. PatternLayout layout = new PatternLayout(); layout.ConversionPattern = layout_pattern_; layout.ActivateOptions(); // create the appender ColoredConsoleAppender appender = new ColoredConsoleAppender(); appender.Name = "NohrosCommonConsoleAppender"; appender.Layout = layout; appender.Target = "Console.Out"; appender.Threshold = Level.All; if (level_colors_ == null) { level_colors_ = GetDefaultLevelsColors(); } for (int i = 0, j = level_colors_.Length; i < j; i++) { // activate the level colors options and add it to the appender. ColoredConsoleAppender.LevelColors level_colors = level_colors_[i]; if (level_colors != null) { level_colors.ActivateOptions(); appender.AddMapping(level_colors); } } appender.ActivateOptions(); nohros_console_logger.Parent.AddAppender(appender); root_repository.Configured = true; logger = LogManager.GetLogger("NohrosConsoleLogger"); }
internal void ApplyConfigurationTo(ILoggerRepository repository) { var hierarchy = repository as Hierarchy; if (hierarchy != null) { _rootLoggerConfiguration.ApplyTo(hierarchy.Root); } foreach (var pair in _childLoggerConfigurations) { var logger = repository.GetLogger(pair.Key) as Logger; if (logger != null) { pair.Value.ApplyTo(logger); } } }
public ApplicationLogger(LogConfiguration configuration, ILoggerRepository loggerRepository) : base(configuration, loggerRepository) { this.Logger = (Logger)loggerRepository.GetLogger("Application"); }
public void Setup() { correlation = new Correlation(CorrelationId, CallerId); log = Substitute.For<ILog>(); logger = Substitute.For<log4net.Core.ILogger>(); log.Logger.Returns(logger); repository = Substitute.For<ILoggerRepository>(); repository.GetLogger(source.GetType()).Returns(log); sut = new LogWriter(repository, source); }
public FrameworkLogger(LogConfiguration configuration, ILoggerRepository loggerRepository) : base(configuration, loggerRepository) { this.Logger = (Logger)loggerRepository.GetLogger("Framework"); }
public HibernateLogger(LogConfiguration configuration, ILoggerRepository loggerRepository) : base(configuration, loggerRepository) { this.Logger = (Logger)loggerRepository.GetLogger("NHibernate.SQL"); }
public static ICustomLog GetLogger(ILoggerRepository respository, string name) { return WrapLogger(respository.GetLogger(name)); }
public t_Loggers GetLogger(string serial) { return(loggerRepository.GetLogger(serial)); }