1- using G3 . AspNetCore . Core . Logging ;
21using Microsoft . AspNetCore . Builder ;
3- using Microsoft . Extensions . DependencyInjection ;
42using Microsoft . Extensions . Hosting ;
53using Microsoft . Extensions . Logging ;
6- using Microsoft . Extensions . Logging . Console ;
74using System . Text . Json ;
85
96namespace G3 . AspNetCore . Core . Extensions ;
@@ -14,32 +11,20 @@ namespace G3.AspNetCore.Core.Extensions;
1411public static class LoggingExtensions
1512{
1613 /// <summary>
17- /// Configures logging with a rate-limited JSON console provider and suppresses high-volume
18- /// framework log categories. Outputs structured JSON per log line so CloudWatch Logs Insights
19- /// can correlate requests by RequestId, TenantId, and other scope properties.
14+ /// Configures structured JSON console logging and suppresses high-volume framework log
15+ /// categories. Outputs one JSON object per log line so CloudWatch Logs Insights can
16+ /// correlate requests by RequestId, TenantId, and other scope properties.
2017 /// </summary>
2118 public static WebApplicationBuilder AddG3Logging ( this WebApplicationBuilder builder )
2219 {
23- // Register JSON formatter and configure options (AddJsonConsole also adds a provider,
24- // which we remove below so we can wrap it in the rate limiter).
20+ builder . Logging . ClearProviders ( ) ;
21+
2522 builder . Logging . AddJsonConsole ( options =>
2623 {
2724 options . IncludeScopes = true ;
2825 options . JsonWriterOptions = new JsonWriterOptions { Indented = false } ;
2926 } ) ;
3027
31- // Remove the provider AddJsonConsole registered; keep the formatter + options.
32- builder . Logging . ClearProviders ( ) ;
33-
34- // Re-add as a rate-limited wrapper around ConsoleLoggerProvider.
35- builder . Logging . Services . AddSingleton < ILoggerProvider > ( sp =>
36- {
37- var consoleProvider = new ConsoleLoggerProvider (
38- sp . GetRequiredService < Microsoft . Extensions . Options . IOptionsMonitor < ConsoleLoggerOptions > > ( ) ,
39- sp . GetServices < ConsoleFormatter > ( ) ) ;
40- return new RateLimitedLoggerProvider ( consoleProvider ) ;
41- } ) ;
42-
4328 builder . Logging . SetMinimumLevel (
4429 builder . Environment . IsProduction ( )
4530 ? LogLevel . Warning
0 commit comments