/// <summary> /// Adds the log4net. /// </summary> /// <param name="factory">The factory.</param> /// <param name="log4NetConfigFile">The log4net Config File.</param> /// <returns>The <see cref="ILoggerFactory"/>.</returns> public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, string log4NetConfigFile, Func <object, Exception, string> exceptionFormatter) { Log4NetProvider provider = new Log4NetProvider(log4NetConfigFile, exceptionFormatter); factory.AddProvider(provider); return(factory); }
/// <summary> /// Adds log4net support using the provided <see cref="Log4NetSettings"/> /// </summary> /// <param name="self">The logger factory to update for log4net support</param> /// <param name="settings">The settings to use for configuring log4net.</param> /// <returns>The passed in logger factory</returns> public static ILoggerFactory AddLog4Net(this ILoggerFactory self, Log4NetSettings settings) { var provider = new Log4NetProvider(); provider.Initialize(settings); self.AddProvider(provider); return(self); }
/// <summary> /// Adds log4net support using the provided <see cref="Log4NetSettings"/> /// </summary> /// <param name="self">The logging builder to update for log4net support</param> /// <param name="settings">The settings to use for configuring log4net.</param> /// <returns>The passed in logging builder</returns> public static ILoggingBuilder AddLog4Net(this ILoggingBuilder self, Log4NetSettings settings) { var provider = new Log4NetProvider(); provider.Initialize(settings); self.AddProvider(provider) .AddFilter <Log4NetProvider>((category, logLevel) => { return(provider.CreateLogger(category).IsEnabled(logLevel)); }); return(self); }
/// <inheritdoc /> public virtual ILoggerProvider Configure() { var patternLayout = new PatternLayout { ConversionPattern = "%utcdate{dd-MM-yyyy HH:mm:ss.ffffff} [%level] %message%newline" }; patternLayout.ActivateOptions(); var consoleAppender = new ConsoleAppender { Layout = patternLayout }; var hierarchy = (Hierarchy)LogManager .CreateRepository("default"); hierarchy.Root .AddAppender(consoleAppender); hierarchy.Root.Level = this.Options.LogLevel .GetLogLevel(); hierarchy.Configured = true; // TODO: Log4Net: Namespace overrides. //foreach (var logLevelOverride in this.Options.LogLevelOverrides) //{ // var nestedHierarchy = (Hierarchy)LogManager // .CreateRepository(logLevelOverride.Namespace); // nestedHierarchy.Root.Level = logLevelOverride.LogLevel // .GetLogLevel(); // nestedHierarchy.Root // .AddAppender(consoleAppender); // nestedHierarchy.Configured = true; //} var providerOptions = new Log4NetProviderOptions { ExternalConfigurationSetup = true, LoggerRepository = hierarchy.Name }; var provider = new Microsoft.Extensions.Logging.Log4NetProvider(providerOptions); return(provider); }
/// <summary> /// Adds the log4net. /// </summary> /// <param name="factory">The factory.</param> /// <param name="log4NetConfigFile">The log4net Config File.</param> /// <returns>The <see cref="ILoggerFactory"/>.</returns> public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, string log4NetConfigFile) { if (factory == null) { throw new ArgumentNullException(nameof(factory)); } if (log4NetConfigFile == null) { throw new ArgumentNullException(nameof(log4NetConfigFile)); } ILoggerProvider provider = new Log4NetProvider(log4NetConfigFile); factory.AddProvider(provider); return(factory); }