dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.43k stars 10.02k forks source link

Custom Operation for UseDeveloperExceptionPage #9159

Closed Edward-Zhou closed 5 years ago

Edward-Zhou commented 5 years ago

Is your feature request related to a problem? Please describe.

I want to log the error to database, for UseExceptionHandler, we could custom it in public static IApplicationBuilder UseExceptionHandler(this IApplicationBuilder app, Action<IApplicationBuilder> configure), but for UseDeveloperExceptionPage, there is no such operation.

Describe the solution you'd like

Provider the Action<IApplicationBuilder> configure in UseDeveloperExceptionPage

davidfowl commented 5 years ago

Are you trying to log specific errors to the database? If not, why not just write a logging provider (or use one like serilog) that supports logging to the database?

Why do you need a way to hook the developer exception page? That's only used when developing locally (and it also logs the error to the logging system).

Edward-Zhou commented 5 years ago

Yes, I am trying to log errors to database, and I also want to log the errors while development environment.

davidfowl commented 5 years ago

@Edward-Zhou Just use a logger provider then.

davidfowl commented 5 years ago

Using something like this:

https://github.com/serilog/serilog-sinks-mssqlserver

Edward-Zhou commented 5 years ago

@davidfowl Is there any specific reason I should not custom it in UseDeveloperExceptionPage middleware like UseExceptionHandler. For logger provider, I will need to implement another middleware with try catch block.

davidfowl commented 5 years ago

Because there's a better way to solve the problem with a system that was designed to do exactly this (log things). Both the developer exception page and the error handler log the exception.

analogrelay commented 5 years ago

As @davidfowl said, this middleware isn't designed for this purpose and we don't have plans to add that functionality at this time.