using Microsoft.Extensions.Configuration;
using System;
// Same namespace as ILoggerFactory, to make these extensions appear
// without the user needing to including our namespace first.
namespace Microsoft.Extensions.Logging
{
///
/// ILoggerFactory extensions
///
public static class ILoggerFactoryExtensions
{
///
/// Adds a Lambda logger provider with default options.
///
/// ILoggerFactory to add Lambda logger to.
/// Updated ILoggerFactory.
[CLSCompliant(false)] // https://github.com/aspnet/Logging/issues/500
public static ILoggerFactory AddLambdaLogger(this ILoggerFactory factory)
{
var options = new LambdaLoggerOptions();
return AddLambdaLogger(factory, options);
}
///
/// Adds a Lambda logger provider with specified options.
///
/// ILoggerFactory to add Lambda logger to.
/// Lambda logging options.
/// Updated ILoggerFactory.
[CLSCompliant(false)] // https://github.com/aspnet/Logging/issues/500
public static ILoggerFactory AddLambdaLogger(this ILoggerFactory factory, LambdaLoggerOptions options)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
var provider = new LambdaILoggerProvider(options);
factory.AddProvider(provider);
return factory;
}
///
/// Adds a Lambda logger provider with options loaded from the "Lambda.Logging" subsection
/// of the specified configuration.
///
/// ILoggerFactory to add Lambda logger to.
/// IConfiguration to use when construction logging options.
/// Updated ILoggerFactory.
[CLSCompliant(false)] // https://github.com/aspnet/Logging/issues/500
public static ILoggerFactory AddLambdaLogger(this ILoggerFactory factory, IConfiguration configuration)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
var options = new LambdaLoggerOptions(configuration);
var provider = new LambdaILoggerProvider(options);
factory.AddProvider(provider);
return factory;
}
///
/// Adds a Lambda logger provider with options loaded from the specified subsection of the
/// configuration section.
///
/// ILoggerFactory to add Lambda logger to.
/// IConfiguration to use when construction logging options.
/// Name of the logging section with required settings.
/// Updated ILoggerFactory.
[CLSCompliant(false)] // https://github.com/aspnet/Logging/issues/500
public static ILoggerFactory AddLambdaLogger(this ILoggerFactory factory, IConfiguration configuration, string loggingSectionName)
{
if (factory == null)
{
throw new ArgumentNullException(nameof(factory));
}
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (string.IsNullOrEmpty(loggingSectionName))
{
throw new ArgumentNullException(nameof(loggingSectionName));
}
var options = new LambdaLoggerOptions(configuration, loggingSectionName);
var provider = new LambdaILoggerProvider(options);
factory.AddProvider(provider);
return factory;
}
}
}