In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people have no idea about how to use Diagnostics middleware in ASP.NET Core. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
Report exception and error messages
Projects created by default will automatically add this paragraph to the Configure method in Startup
If (env.IsDevelopment ()) {app.UseDeveloperExceptionPage (); app.UseBrowserLink ();}
Else {app.UseExceptionHandler ("/ Home/Error");}
This is the reporting and handling of exception information.
A detailed error message app.UseDeveloperExceptionPage () is displayed in the development environment; in a non-development environment, jump to the app.UseExceptionHandler ("/ Home/Error"); / Home/Error page.
Put app.UseDeveloperExceptionPage (); outside the if if you want to keep displaying error messages. Or after the release, set the corresponding system environment to Development to display the error message.
EF Core is used in the project. You can add app.UseDatabaseErrorPage (); to display information about EF Core.
Welcome page
Add the Configure method in Startup.cs: app.UseWelcomePage ()
The following page will be displayed when you start the program. There is an extension method to specify the corresponding page.
HTTP error code page
Related errors such as 404 or 500 in the default program will not display the page, only the corresponding code will be returned.
Also added to the Configure method in Startup.cs: app.UseStatusCodePages ()
Visiting a page that does not exist will be displayed as follows.
Here is a simple custom error message
App.UseStatusCodePages ("text/plain", "Error, status code: {0}\ r LineZero")
You can also use the
App.UseStatusCodePagesWithRedirects ("~ / errors/ {0}"); / / relative root path
App.UseStatusCodePagesWithRedirects ("/ base/errors/ {0}"); / / absolute path
You can also use the
App.UseStatusCodePagesWithReExecute ("/ error/http {0}")
The difference between the above two is jump and execution.
Log view Elm
Log viewing is also a function of Diagnostics middleware. It's also convenient to use.
You need to add an additional Microsoft.AspNetCore.Diagnostics.Elm package.
After installing the package, open the Startup.cs and first join the service in the ConfigureServices method.
Services.AddElm (elmOptions = > {elmOptions.Filter = (loggerName, loglevel) = > loglevel = = LogLevel.Debug;})
Filter log level is Debug
Then add the Configure method.
App.UseElmPage (); app.UseElmCapture ()
App.UseElmPage (); displays the page for the specified log, app.UseElmCapture (); logs.
By running the program to access http://localhost:5000/Elm, you can view some information records.
After reading the above, have you mastered how to use Diagnostics middleware in ASP.NET Core? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.