ASP requests hang if ILogger throws
See original GitHub issueDescription
ASP.NET requests hang indefinitely if the ILogger being used throws a NotImplementedException from the BeginScope method.
To Reproduce
Steps to reproduce the behavior: Repro can be found in minimal repository here: https://github.com/jroggeman/aspnetbug
Basic overview:
- Using ASP.NET Core 2.2.204
- Create a new ASP.NET web application
- Create a new dotnet standard library (
netstandard2.0) - In the library, implement a minimal console logger and provider using
ILoggerandILoggerProviderinterface. Make sureBeginScopemethod throws aNotImplementedException - In the web app, register the provider and inject it in to the default controller
dotnet runthe app and request a page from the controller
Observe that the request will hang indefinitely with no output from ASP
Expected behavior
An error is indicated somehow - a 500 is returned from ASP, ASP prints a stack trace,
Additional context
I understand you probably shouldn’t inject incomplete implementations of interfaces into ASP 😃 We’ve stopped doing that and all is fine. But I would also expect that ASP would realize that this was an error somehow and handle it, rather than hanging the request. So just in case this type of issue is more pervasive, I figured I’d throw it over to you all.
dotnet info:
.NET Core SDK (reflecting any global.json):
Version: 2.2.204
Commit: 8757db13ec
Runtime Environment:
OS Name: Windows
OS Version: 10.0.17763
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.2.204\
Host (useful for support):
Version: 2.2.5
Commit: 0a3c9209c0
.NET Core SDKs installed:
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.604 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]
2.2.204 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
Edit: Repo link for bug repro was committed one level too deep so was missing the actual logging library. Fixed now.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (13 by maintainers)

Top Related StackOverflow Question
Let’s at a minimum look at making sure that Kestrel/IIS kill the connection when
CreateContextthrows. Logging is really hard here because we don’t know if it’ll work.I think we should consider what happens when things in
IHttpApplication.CreateContextthrow. This goes a little beyond Logging since it’s just the thing causing the problem here. We seem to hang the entire request, and not report anything at all.