-
Notifications
You must be signed in to change notification settings - Fork 641
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
Fix logging exceptions from background thread #6273
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this looks fine. Could we track Elmah and AI diverging? There may already be an issue since Elmah sometimes has this AI doesn't have. Please get one more sign off.
@@ -34,7 +37,7 @@ protected override Task SendMessageAsync(MailMessage mailMessage) | |||
catch (Exception ex) | |||
{ | |||
// Log but swallow the exception. | |||
QuietLog.LogHandledException(ex); | |||
telemetryService.TrackException(ex, _ => { }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not use the overload that doesn't require an Action
?
We have a monitor on exception in Elmah which can trigger when exceptions go over a certain point. Since we know |
The previous code would try to resolve a service from DI in a background thread without a HttpContext, and Autofac would throw an exception. So, pass the required service to the background thread when it can be resolved.
23e8c69
to
e44825c
Compare
} | ||
|
||
private ErrorLog errorLog; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: readonly
QuietLog uses Elmah, which uses DI resolving at log time, rather than being contructed at HTTP request time. Autofac MVC's lifetime manager requires a HttpContext, which is null in a background thread, so there was no good/easy way to resolve the Elmah logger in a background thread. Logging only to app insights instead.