/// <summary> /// Initializes a new instance of the <see cref="Log4NetProvider"/> class. /// </summary> /// <param name="options">The options.</param> /// <exception cref="ArgumentNullException">options</exception> /// <exception cref="NotSupportedException">Wach cannot be true when you are overwriting config file values with values from configuration section.</exception> public Log4NetProvider(Log4NetProviderOptions options) { this.SetOptionsIfValid(options); var loggingAssembly = GetLoggingReferenceAssembly(); this.CreateLoggerRepository(loggingAssembly) .ConfigureLog4NetLibrary(loggingAssembly); }
/// <summary> /// Creates the logger implementation. /// </summary> /// <param name="name">The name.</param> /// <returns>The <see cref="Log4NetLogger"/> instance.</returns> private Log4NetLogger CreateLoggerImplementation(string name) { var options = new Log4NetProviderOptions { Name = name, LoggerRepository = this.loggerRepository.Name, }; options.ScopeFactory = new Log4NetScopeFactory(new Log4NetScopeRegistry()); return(new Log4NetLogger(options)); }
/// <summary> /// Ensures that provided options combinations are valid, and sets the class field if everything is ok. /// </summary> /// <param name="options">The options to validate.</param> /// <exception cref="NotSupportedException"> /// Throws when the Watch option is set and there are properties to override. /// </exception> /// <exception cref="ArgumentNullException"> /// Throws when the options parameter is null. /// </exception> private void SetOptionsIfValid(Log4NetProviderOptions options) { if (options == null) { throw new ArgumentNullException(nameof(options)); } if (options.Watch && options.PropertyOverrides.Any()) { throw new NotSupportedException("Wach cannot be true when you are overwriting config file values with values from configuration section."); } this.options = options; }
/// <summary> /// Initializes a new instance of the <see cref="Log4NetLogger"/> class. /// </summary> /// <param name="options">The log4net provider options.</param> public Log4NetLogger(Log4NetProviderOptions options) { this.options = options ?? throw new ArgumentNullException(nameof(options)); this.log = LogManager.GetLogger(options.LoggerRepository, options.Name); }