This repository was archived by the owner on Dec 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Always log startup exceptions #1153
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,21 +191,26 @@ private RequestDelegate BuildApplication() | |
|
||
return builder.Build(); | ||
} | ||
catch (Exception ex) when (_options.CaptureStartupErrors) | ||
catch (Exception ex) | ||
{ | ||
// EnsureApplicationServices may have failed due to a missing or throwing Startup class. | ||
if (_applicationServices == null) | ||
{ | ||
_applicationServices = _applicationServiceCollection.BuildServiceProvider(); | ||
} | ||
|
||
EnsureServer(); | ||
|
||
// Write errors to standard out so they can be retrieved when not in development mode. | ||
Console.Out.WriteLine("Application startup exception: " + ex.ToString()); | ||
var logger = _applicationServices.GetRequiredService<ILogger<WebHost>>(); | ||
logger.ApplicationError(ex); | ||
|
||
if (!_options.CaptureStartupErrors) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the braces There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed the braces - sorry for that! |
||
{ | ||
throw; | ||
} | ||
|
||
EnsureServer(); | ||
|
||
// Generate an HTML error page. | ||
var hostingEnv = _applicationServices.GetRequiredService<IHostingEnvironment>(); | ||
var showDetailedErrors = hostingEnv.IsDevelopment() || _options.DetailedErrors; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
We don't still want the ConsoleWriteline do we?
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.
I'd keep it as people probably don't use the Console Logger in non-development environments and having the console output as an additional troubleshooting mechanism could be helpful.
E.g. in Service Fabric you can redirect console output to a file - by keeping this Console.WriteLine one would at least get the startup messages ("Listening on...") and any startup exceptions.