Skip to content

Commit 8fd539d

Browse files
committed
Fallback RequestPath for when IHttpRequestFeature.RawTarteg is empty instead of null
1 parent d9087b6 commit 8fd539d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Serilog.AspNetCore/AspNetCore/RequestLoggingMiddleware.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ static double GetElapsedMilliseconds(long start, long stop)
106106

107107
static string GetPath(HttpContext httpContext)
108108
{
109-
return httpContext.Features.Get<IHttpRequestFeature>()?.RawTarget ?? httpContext.Request.Path.ToString();
109+
var requestPath = httpContext.Features.Get<IHttpRequestFeature>()?.RawTarget;
110+
if (string.IsNullOrWhiteSpace(requestPath))
111+
{
112+
requestPath = httpContext.Request.Path.ToString();
113+
}
114+
115+
return requestPath;
110116
}
111117
}
112118
}

0 commit comments

Comments
 (0)