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