@@ -230,7 +230,7 @@ await RunAsync(
230230 const string Content = "Client: hello!" ;
231231
232232 using var content = new StringContent ( Content , null , requestContentType ) ;
233- using var response = await client . PostAsync ( "/" , content ) . ConfigureAwait ( false ) ;
233+ using var response = await client . PostAsync ( "/myroute/123 " , content ) . ConfigureAwait ( false ) ;
234234 Assert . True ( response . IsSuccessStatusCode ) ;
235235
236236 await WaitForLogRecordsAsync ( logCollector , _defaultLogTimeout ) ;
@@ -267,6 +267,48 @@ await RunAsync(
267267 } ) ;
268268 }
269269
270+ [ Fact ]
271+ public async Task HttpLogging_WhenIncludeUnmatchedRoutes_LogRequestPath ( )
272+ {
273+ await RunAsync (
274+ LogLevel . Information ,
275+ services => services . AddHttpLogging ( x =>
276+ {
277+ x . MediaTypeOptions . Clear ( ) ;
278+ x . MediaTypeOptions . AddText ( "text/*" ) ;
279+ x . LoggingFields |= HttpLoggingFields . RequestBody ;
280+ } ) . AddHttpLoggingRedaction ( options => options . IncludeUnmatchedRoutes = true ) ,
281+ async ( logCollector , client ) =>
282+ {
283+ const string Content = "Client: hello!" ;
284+
285+ using var content = new StringContent ( Content , null , MediaTypeNames . Text . Html ) ;
286+ using var response = await client . PostAsync ( "/myroute/123" , content ) . ConfigureAwait ( false ) ;
287+ Assert . True ( response . IsSuccessStatusCode ) ;
288+
289+ await WaitForLogRecordsAsync ( logCollector , _defaultLogTimeout ) ;
290+
291+ Assert . Equal ( 1 , logCollector . Count ) ;
292+ Assert . Null ( logCollector . LatestRecord . Exception ) ;
293+ Assert . Equal ( LogLevel . Information , logCollector . LatestRecord . Level ) ;
294+ Assert . Equal ( LoggingCategory , logCollector . LatestRecord . Category ) ;
295+
296+ var responseStatus = ( ( int ) response . StatusCode ) . ToInvariantString ( ) ;
297+ var state = logCollector . LatestRecord . StructuredState ! ;
298+
299+ Assert . DoesNotContain ( state , x => x . Key == HttpLoggingTagNames . ResponseBody ) ;
300+ Assert . DoesNotContain ( state , x => x . Key . StartsWith ( HttpLoggingTagNames . RequestHeaderPrefix ) ) ;
301+ Assert . DoesNotContain ( state , x => x . Key . StartsWith ( HttpLoggingTagNames . ResponseHeaderPrefix ) ) ;
302+ Assert . Single ( state , x => x . Key == HttpLoggingTagNames . Host && ! string . IsNullOrEmpty ( x . Value ) ) ;
303+ Assert . Single ( state , x => x . Key == HttpLoggingTagNames . Path && x . Value == "/myroute/123" ) ;
304+ Assert . Single ( state , x => x . Key == HttpLoggingTagNames . StatusCode && x . Value == responseStatus ) ;
305+ Assert . Single ( state , x => x . Key == HttpLoggingTagNames . Method && x . Value == HttpMethod . Post . ToString ( ) ) ;
306+ Assert . Single ( state , x => x . Key == HttpLoggingTagNames . Duration &&
307+ x . Value != null &&
308+ int . Parse ( x . Value , CultureInfo . InvariantCulture ) == SlashRouteProcessingTimeMs ) ;
309+ } ) ;
310+ }
311+
270312 [ Fact ]
271313 public async Task HttpLogging_WhenLogLevelInfo_LogRequestStart ( )
272314 {
0 commit comments