@@ -25,25 +25,32 @@ public sealed class RequestResponseLoggerFilterAttribute : ActionFilterAttribute
2525 private readonly string _correlationIdHeaderKey ;
2626 private readonly string _transactionIdHeaderKey ;
2727 private readonly string _endToEndHeaderKey ;
28+ private readonly List < string > _redactedHeaders ;
2829
2930 public RequestResponseLoggerFilterAttribute ( IConfiguration config , ILogger logger )
30- : this ( logger ,
31+ : this ( logger ,
3132 config . GetValue < string > ( "Logging:LogLevel:Default" ) == "Trace" || config . GetValue < string > ( "Logging:LogLevel:Default" ) == "Debug" ,
3233 config . GetValue < bool > ( "Logging:EnableHttpContextBodyLogging" ) ,
33- config . GetValue < string > ( "Application:CorrelationIdHeaderKey" ) ,
34- config . GetValue < string > ( "Application:TransactionIdHeaderKey" ) ,
35- config . GetValue < string > ( "Application:EndToEndTrackingHeaderKey" ) )
36- {
37- }
34+ config . GetValue < string > ( "Application:CorrelationIdHeaderKey" ) ?? config . GetValue < string > ( "ItTelemetryExtensions:CorrelationKey" ) ?? TelemetryConstant . HEADER_DEFAULT_CORRELATION_KEY ,
35+ config . GetValue < string > ( "Application:TransactionIdHeaderKey" ) ?? config . GetValue < string > ( "ItTelemetryExtensions:TransactionKey" ) ?? TelemetryConstant . HEADER_DEFAULT_TRANSACTION_KEY ,
36+ config . GetValue < string > ( "Application:EndToEndTrackingHeaderKey" ) ?? config . GetValue < string > ( "ItTelemetryExtensions:EndToEndKey" ) ?? TelemetryConstant . HEADER_DEFAULT_E2E_KEY ,
37+ config . GetValue < string > ( "Logging:RedactedHeaders" ) )
38+ { }
3839
39- private RequestResponseLoggerFilterAttribute ( ILogger logger , bool isVerboseLoggingEnabled , bool isHttpContextBodyLoggingEnabled , string correlationIdHeaderKey , string transactionIdHeaderKey , string e2eTrackingIdHeaderKey )
40+ private RequestResponseLoggerFilterAttribute ( ILogger logger , bool isVerboseLoggingEnabled , bool isHttpContextBodyLoggingEnabled , string correlationIdHeaderKey , string transactionIdHeaderKey , string e2eTrackingIdHeaderKey , string redactedHeaders )
4041 {
4142 _logger = logger ;
4243 _isVerboseLoggingEnabled = isVerboseLoggingEnabled ;
4344 _isHttpContextBodyLoggingEnabled = isHttpContextBodyLoggingEnabled ;
4445 _correlationIdHeaderKey = correlationIdHeaderKey ;
4546 _transactionIdHeaderKey = transactionIdHeaderKey ;
4647 _endToEndHeaderKey = e2eTrackingIdHeaderKey ;
48+ _redactedHeaders = new List < string > ( ) { "Authorization" } ;
49+ if ( ! string . IsNullOrWhiteSpace ( redactedHeaders ) )
50+ {
51+ string [ ] splitRedactedHeaders = redactedHeaders . Split ( ',' ) ;
52+ _redactedHeaders . AddRange ( splitRedactedHeaders ) ;
53+ }
4754 }
4855
4956 public override void OnActionExecuting ( ActionExecutingContext context )
@@ -125,16 +132,16 @@ private Dictionary<string, string> GetLogPropertiesFromRequest(HttpRequest reque
125132
126133 foreach ( var header in request . Headers )
127134 {
128- if ( header . Key == "Authorization" )
135+ if ( _redactedHeaders != null && _redactedHeaders . Contains ( header . Key ) )
129136 logProperties . AddOrUpdate ( $ "Request:Header:{ header . Key } ", TelemetryConstant . REDACTED ) ;
130137 else
131138 logProperties . AddOrUpdate ( $ "Request:Header:{ header . Key } ", string . Join ( "," , header . Value ) ) ;
132139 }
133- logProperties . AddOrUpdate ( "Request:Method" , request . Method ) ;
134- logProperties . AddOrUpdate ( "Request:Protocol" , request . Protocol ) ;
135- logProperties . AddOrUpdate ( "Request:Scheme" , request . Scheme ) ;
136- logProperties . AddOrUpdate ( "Request:Host" , request . Host . Value ) ;
137- logProperties . AddOrUpdate ( "Request:Path" , request . Path . Value ) ;
140+ logProperties . AddOrUpdate ( "Request:Method" , request . Method ) ;
141+ logProperties . AddOrUpdate ( "Request:Protocol" , request . Protocol ) ;
142+ logProperties . AddOrUpdate ( "Request:Scheme" , request . Scheme ) ;
143+ logProperties . AddOrUpdate ( "Request:Host" , request . Host . Value ) ;
144+ logProperties . AddOrUpdate ( "Request:Path" , request . Path . Value ) ;
138145 logProperties . AddOrUpdate ( "Request:QueryString" , request . QueryString . HasValue ? request . QueryString . Value : string . Empty ) ;
139146
140147 if ( request . Method != HttpMethod . Get . ToString ( ) && _isHttpContextBodyLoggingEnabled )
0 commit comments