private Log4NetProvider(string log4NetConfigFile, bool watch, IConfigurationSection configurationSection) { if (watch && configurationSection != null) { throw new NotSupportedException("Wach cannot be true if you are overwriting config file values with values from configuration section."); } _options = Log4NetProviderOptions.Default; Assembly repositoryAssembly = Assembly.GetExecutingAssembly(); if (repositoryAssembly == null) { repositoryAssembly = GetCallingAssemblyFromStartup(); } _loggerRepository = LogManager.CreateRepository(repositoryAssembly, typeof(Hierarchy)); if (watch) { XmlConfigurator.ConfigureAndWatch(_loggerRepository, new FileInfo(Path.GetFullPath(log4NetConfigFile))); } else { XmlDocument configXml = ParseLog4NetConfigFile(log4NetConfigFile); if (configurationSection != null) { configXml = UpdateNodesWithAdditionalConfiguration(configXml, configurationSection); } XmlConfigurator.Configure(_loggerRepository, configXml.DocumentElement); } }
public static Configuration UseLog4Net(this Configuration configuration, Log4NetProviderOptions options = null) { ObjectProviderFactory.Instance.Populate(UseLog4Net(new ServiceCollection(), options)); return(configuration); }
public Log4NetProvider(Log4NetProviderOptions options) { _options = options ?? Log4NetProviderOptions.Default; var configFile = GetLog4NetConfigFile(_options.ConfigFile); var repositoryName = Configuration.Get("app") ?? Assembly.GetCallingAssembly() .FullName; _loggerRepository = LogManager.GetAllRepositories() .FirstOrDefault(r => r.Name == repositoryName) ?? LogManager.CreateRepository(repositoryName); XmlConfigurator.ConfigureAndWatch(_loggerRepository, configFile); }
public static IServiceCollection UseLog4Net(this IServiceCollection services, LogLevel logLevel, Log4NetProviderOptions options = null) { services.AddLogging(config => { var loggerConfiguration = Configuration.Instance.GetSection("logging"); if (loggerConfiguration.Exists()) { config.AddConfiguration(loggerConfiguration); } config.SetMinimumLevel(logLevel); config.AddProvider(new Log4NetProvider(options)); }); return(services); }
public static IServiceCollection AddLog4Net(this IServiceCollection services, Log4NetProviderOptions options = null) { services.AddLogging(config => { var loggerConfiguration = Configuration.Instance.GetSection("logging"); if (loggerConfiguration.Exists()) { config.AddConfiguration(loggerConfiguration); if (Enum.TryParse <LogLevel>(loggerConfiguration.GetSection("LogLevel")["Default"], out var logLevel)) { config.SetMinimumLevel(logLevel); } } config.AddProvider(new Log4NetProvider(options ?? Log4NetProviderOptions.Default)); }); return(services); }
public Log4NetProvider(Log4NetProviderOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); if (_options.Watch && _options.PropertyOverrides.Any()) { throw new NotSupportedException("Watch cannot be true when you are overwriting config file values with values from configuration section."); } if (string.IsNullOrEmpty(_options.LoggerRepository)) { Assembly repositoryAssembly = Assembly.GetExecutingAssembly(); _loggerRepository = LogManager.CreateRepository(repositoryAssembly, typeof(Hierarchy)); } else { _loggerRepository = LogManager.CreateRepository(_options.LoggerRepository, typeof(Hierarchy)); } string str = _options.ConfigFile; if (!Path.IsPathRooted(str)) { str = Path.Combine(AppContext.BaseDirectory, str); } string fullPath = Path.GetFullPath(str); if (_options.Watch) { XmlConfigurator.ConfigureAndWatch(_loggerRepository, new FileInfo(fullPath)); } else { XmlDocument configXmlDocument = ParseLog4NetConfigFile(fullPath); if (_options.PropertyOverrides != null && _options.PropertyOverrides.Any()) { configXmlDocument = UpdateNodesWithOverridingValues(configXmlDocument, _options.PropertyOverrides); } XmlConfigurator.Configure(_loggerRepository, configXmlDocument.DocumentElement); } }
public Log4NetLogger(string repositoryName, string name, Log4NetProviderOptions options) { _options = options; _log = LogManager.GetLogger(repositoryName, name); }
public static void UseLog4Net(this ILoggerFactory loggerFactory, Log4NetProviderOptions options = null) { loggerFactory.AddProvider(new Log4NetProvider(options)); }
public static void AddLog4Net(this ILoggerFactory loggerFactory, Log4NetProviderOptions options = null) { loggerFactory.AddProvider(new Log4NetProvider(options ?? Log4NetProviderOptions.Default)); }
private Log4NetLogger CreateLoggerImplementation(string name, Log4NetProviderOptions options) { return(new Log4NetLogger(_loggerRepository.Name, name, options)); }