using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace Microsoft.Extensions.Logging
{
///
/// The log4net extensions class.
///
public static class Log4NetExtensions
{
///
/// Adds the log4net.
///
/// The factory.
/// The with added Log4Net provider
public static ILoggerFactory AddLog4Net(this ILoggerFactory factory)
=> factory.AddLog4Net(new Log4NetProviderOptions());
///
/// Adds the log4net.
///
/// The factory.
/// The log4net Config File.
/// The after adding the log4net provider.
public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, string log4NetConfigFile)
=> factory.AddLog4Net(log4NetConfigFile, false);
///
/// Adds the log4net logging provider.
///
/// The factory.
/// The log4 net configuration file.
/// if set to true [watch].
/// The after adding the log4net provider.
public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, string log4NetConfigFile, bool watch)
=> factory.AddLog4Net(new Log4NetProviderOptions(log4NetConfigFile, watch));
///
/// Adds the log4net logging provider.
///
/// The logger factory.
/// The options for log4net provider.
/// The after adding the log4net provider.
public static ILoggerFactory AddLog4Net(this ILoggerFactory factory, Log4NetProviderOptions options)
{
factory.AddProvider(new Log4NetProvider(options));
return factory;
}
///
/// Adds the log4net logging provider.
///
/// The logging builder instance.
/// The passed as parameter with the new provider registered.
public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder)
{
var options = new Log4NetProviderOptions();
return builder.AddLog4Net(options);
}
///
/// Adds the log4net logging provider.
///
/// The logging builder instance.
/// The log4net Config File.
/// The passed as parameter with the new provider registered.
public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder, string log4NetConfigFile)
{
var options = new Log4NetProviderOptions(log4NetConfigFile);
return builder.AddLog4Net(options);
}
///
/// Adds the log4net logging provider.
///
/// The logging builder instance.
/// The log4net Config File.
/// if set to true, the configuration will be reloaded when the xml configuration file changes.
///
/// The passed as parameter with the new provider registered.
///
public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder, string log4NetConfigFile, bool watch)
{
var options = new Log4NetProviderOptions(log4NetConfigFile, watch);
return builder.AddLog4Net(options);
}
///
/// Adds the log4net logging provider.
///
/// The logging builder instance.
/// The options.
/// The passed as parameter with the new provider registered.
public static ILoggingBuilder AddLog4Net(this ILoggingBuilder builder, Log4NetProviderOptions options)
{
builder.Services.Replace(ServiceDescriptor.Singleton(sp => new Log4NetProvider(options, sp)));
return builder;
}
}
}