@@ -26,8 +26,6 @@ internal class ResponseAutoWrapMiddleware
2626
2727 private readonly ILogger _logger ;
2828
29- private readonly ResponseAutoWrapMiddlewareOptions . MiddlewareExceptionCaptured _middlewareExceptionCaptured ;
30-
3129 private readonly RequestDelegate _next ;
3230
3331 private readonly bool _notCatchExceptions ;
@@ -92,7 +90,6 @@ public ResponseAutoWrapMiddleware(RequestDelegate next,
9290 _notCatchExceptions = ! options . CatchExceptions ;
9391 _throwCaughtExceptions = options . ThrowCaughtExceptions ;
9492 _ignoreOptionsRequest = options . IgnoreOptionsRequest ;
95- _middlewareExceptionCaptured = options . OnMiddlewareExceptionCaptured ?? LogMiddlewareException ;
9693
9794 var delegateCollection = GetService < ResponseAutoWrapperWorkDelegateCollection > ( ) ;
9895
@@ -126,8 +123,6 @@ public async Task InvokeAsync(HttpContext context)
126123 throw ;
127124 }
128125
129- var doesExceptionWrapped = false ;
130-
131126 //响应未开始,则包装响应
132127 if ( ! context . Response . HasStarted
133128 && ! context . RequestAborted . IsCancellationRequested )
@@ -136,7 +131,6 @@ public async Task InvokeAsync(HttpContext context)
136131 if ( response is not null )
137132 {
138133 await WriteResponseWithFormatterAsync ( context , response ) ;
139- doesExceptionWrapped = true ;
140134 }
141135 }
142136 else //无法对响应进行包装,此时强制向上层抛出异常
@@ -150,7 +144,7 @@ public async Task InvokeAsync(HttpContext context)
150144 }
151145 else //不抛出异常时,触发回调
152146 {
153- _middlewareExceptionCaptured ( context . Request , ex , doesExceptionWrapped ) ;
147+ LogMiddlewareException ( context . Request , ex ) ;
154148 }
155149 }
156150 finally
@@ -178,8 +172,7 @@ public async Task InvokeAsync(HttpContext context)
178172 /// </summary>
179173 /// <param name="request">出现异常的请求</param>
180174 /// <param name="exception">异常</param>
181- /// <param name="hasExceptionWrapped">异常是否已包装</param>
182- private void LogMiddlewareException ( HttpRequest request , Exception exception , in bool hasExceptionWrapped )
175+ private void LogMiddlewareException ( HttpRequest request , Exception exception )
183176 {
184177 //https://github.com/dotnet/aspnetcore/tree/8dd33378697e6f8ca89116170ec3046c185724b6/src/Hosting/Hosting/src/Internal/HostingRequestStartingLog.cs
185178 _logger . LogError ( exception , "Request error {Protocol} {Method} {Scheme}://{Host}{PathBase}{Path}{QueryString} {ContentType} {ContentLength}" ,
0 commit comments