33
44using Microsoft . Extensions . Logging ;
55using Microsoft . Extensions . Logging . Abstractions ;
6+ using Microsoft . Extensions . Options ;
67
78namespace Aspire . Hosting . Pipelines ;
89
@@ -16,6 +17,16 @@ namespace Aspire.Hosting.Pipelines;
1617internal sealed class PipelineLoggerProvider : ILoggerProvider
1718{
1819 private static readonly AsyncLocal < StepLoggerHolder ? > s_currentLogger = new ( ) ;
20+ private readonly PipelineLoggingOptions _options ;
21+
22+ /// <summary>
23+ /// Initializes a new instance of the <see cref="PipelineLoggerProvider"/> class.
24+ /// </summary>
25+ /// <param name="options">The pipeline logging options.</param>
26+ public PipelineLoggerProvider ( IOptions < PipelineLoggingOptions > options )
27+ {
28+ _options = options . Value ;
29+ }
1930
2031 /// <summary>
2132 /// Gets or sets the current logger for the executing pipeline step.
@@ -39,7 +50,7 @@ public static ILogger CurrentLogger
3950
4051 /// <inheritdoc/>
4152 public ILogger CreateLogger ( string categoryName ) =>
42- new PipelineLogger ( ( ) => CurrentLogger ) ;
53+ new PipelineLogger ( ( ) => CurrentLogger , _options ) ;
4354
4455 /// <inheritdoc/>
4556 public void Dispose ( )
@@ -61,9 +72,9 @@ private sealed class StepLoggerHolder
6172 /// <remarks>
6273 /// This logger acts as a proxy and dynamically resolves the current logger on each operation,
6374 /// allowing the target logger to change between calls.
64- /// When logging exceptions, stack traces are only included when the log level is Debug or Trace.
75+ /// When logging exceptions, stack traces are only included when the configured minimum log level is Debug or Trace.
6576 /// </remarks>
66- private sealed class PipelineLogger ( Func < ILogger > currentLoggerAccessor ) : ILogger
77+ private sealed class PipelineLogger ( Func < ILogger > currentLoggerAccessor , PipelineLoggingOptions options ) : ILogger
6778 {
6879 /// <inheritdoc/>
6980 public IDisposable ? BeginScope < TState > ( TState state ) where TState : notnull =>
@@ -78,9 +89,9 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
7889 {
7990 var logger = currentLoggerAccessor ( ) ;
8091
81- // If there's an exception and the log level is not Debug or Trace , exclude the exception from the log
92+ // If there's an exception and we should not include exception details , exclude the exception from the log
8293 // to avoid cluttering production logs with stack traces
83- if ( exception is not null && logLevel >= LogLevel . Debug )
94+ if ( exception is not null && ! options . IncludeExceptionDetails )
8495 {
8596 logger . Log ( logLevel , eventId , state , null , formatter ) ;
8697 }
0 commit comments