Class PowertoolsLoggingBuilderExtensions
Extension methods to configure and add the Powertools logger to an ILoggingBuilder.
Inherited Members
Namespace: AWS.Lambda.Powertools.Logging
Assembly: AWS.Lambda.Powertools.Logging.dll
Syntax
public static class PowertoolsLoggingBuilderExtensions
Remarks
This class provides methods to integrate the AWS Lambda Powertools logging capabilities with the standard .NET logging framework.
Examples
Basic usage:
builder.Logging.AddPowertoolsLogger();
Methods
AddPowertoolsLogger(ILoggingBuilder, Action<PowertoolsLoggerConfiguration>, bool)
Adds the Powertools logger to the logging builder with default configuration.
Declaration
public static ILoggingBuilder AddPowertoolsLogger(this ILoggingBuilder builder, Action<PowertoolsLoggerConfiguration> configure, bool clearExistingProviders = false)
Parameters
Type | Name | Description |
---|---|---|
ILoggingBuilder | builder | The logging builder to configure. |
Action<PowertoolsLoggerConfiguration> | configure | |
bool | clearExistingProviders | Opt-in to clear providers for Powertools-only output |
Returns
Type | Description |
---|---|
ILoggingBuilder | The logging builder for further configuration. |
Remarks
This method registers the Powertools logger with default settings. The logger will output structured JSON logs that integrate well with AWS CloudWatch and other log analysis tools.
Examples
Add the Powertools logger to your Lambda function:
<pre><code class="lang-csharp">var builder = new HostBuilder()
.ConfigureLogging(logging =>
{
logging.AddPowertoolsLogger();
});</code></pre>
Using with minimal API:
<pre><code class="lang-csharp">var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddPowertoolsLogger();</code></pre>
With custom configuration:
builder.Logging.AddPowertoolsLogger(options =>
{
options.MinimumLogLevel = LogLevel.Information;
options.LoggerOutputCase = LoggerOutputCase.PascalCase;
options.IncludeLogLevel = true;
});
With log buffering:
<pre><code class="lang-csharp">builder.Logging.AddPowertoolsLogger(options =>
{
options.LogBuffering = new LogBufferingOptions
{
Enabled = true,
BufferAtLogLevel = LogLevel.Debug
};
});</code></pre>
AddPowertoolsLogger(ILoggingBuilder, bool)
Adds the Powertools logger to the logging builder with default configuration.
Declaration
public static ILoggingBuilder AddPowertoolsLogger(this ILoggingBuilder builder, bool clearExistingProviders = false)
Parameters
Type | Name | Description |
---|---|---|
ILoggingBuilder | builder | The logging builder to configure. |
bool | clearExistingProviders | Opt-in to clear providers for Powertools-only output |
Returns
Type | Description |
---|---|
ILoggingBuilder | The logging builder for further configuration. |
Remarks
This method registers the Powertools logger with default settings. The logger will output structured JSON logs that integrate well with AWS CloudWatch and other log analysis tools.
Examples
Add the Powertools logger to your Lambda function:
var builder = new HostBuilder()
.ConfigureLogging(logging =>
{
logging.AddPowertoolsLogger();
});
Using with minimal API:
var builder = WebApplication.CreateBuilder(args);
builder.Logging.AddPowertoolsLogger();