public Settings() { // initialize the loggerfactory _loggerFactory = new Lazy<ILoggerFactory>(() => { // copy all loggers from the Configuration var factory = new LoggerFactory(); ConfigSettings.Loggers.ForEach(l => factory.AddLogger(l.GetType().Name, l)); return factory; }); RestrictiveMappingMode = RestrictiveMode.Log; }
public ConfigurationSettings() { var loggers = new List<ILogger>(); // add loggers that are defined in the configurationsection in the app.config var section = ConfigurationManager.GetSection("PersistenceMap") as PersistenceMapSection; if (section != null) { foreach (var element in section.Loggers) { var type = Type.GetType(element.Type); if (type != null) { var instance = type.CreateInstance() as ILogger; if (instance != null) { loggers.Add(instance); Trace.WriteLine(string.Format("## PersistenceMap - Added Logger: {0} defined by the configuration", instance.GetType())); } else { var loggerFactory = new LoggerFactory(); var logger = loggerFactory.CreateLogger(); var message = string.Format("Logger {0} cannot be created because the Type does not exist or does not derive from {1}.", element.Type, typeof(ILogger).Name); logger.Write(message, "Configuration error", "Configuration", DateTime.Now); Trace.WriteLine(string.Format("#### PersistenceMap - Configuration error: {0}", message)); } } } } Loggers = loggers; }