Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpContext - Extended ObjectDisposedException handling #630

Merged
merged 1 commit into from
Jan 26, 2021

Conversation

snakefoot
Copy link
Contributor

@snakefoot snakefoot commented Jan 26, 2021

Suppresses ObjectDisposedException when HttpContext is no longer active (Avoid crashing when NLog users are wrongly using ThrowExceptions=true). Usually caused by NLog-users scheduling work on background-thread that is not awaited so it is runnng after HttpRequest has completed.

Alternative workaround to awaiting the background-task is to suppress the capture of thread-execution-context, so the HttpContext doesn't travel to the background-thread:

using (ExecutionContext.SuppressFlow())
{
    Task.Run(() => {});
}

The correct way of handling this is to ensure logging from non-awaited background-tasks doesn't reach Layout-logic that includes ${aspnet-request}-Layout-logic (Redirect to NLog targets with simple Layout-logic).

@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ASP.NET Core ASP.NET Core - all versions enhancement size/M
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants