"Good" ASP.net stack traces in release configuration or how to get violation code

If I have an application running on ASP.net and I have debug and stacktrace included in web.config, I get a really good error screen telling me which code was causing the error.

Unfortunately, on a live system where debugging is set to false, the yellow death screen is completely useless, even when stack tracing is turned on, it does not show the line where the error occurred (which seems obvious since there should be no debugging information).

I'm just wondering if there is a way to get good error information without having to include debug = true in the web.config file. This should not be an improvement on the Yellow screen, I can also wrap code that I suspect offended in the try..catch block, but then inside the catch block, is there a way to get the actual code that caused the error?

As you can suspect, this applies to a situation where an error occurs only during the production process and the remote debugger is unavailable :(

Edit: this refers to a “normal” exception, such as a System.ArgumentOutOfRangeException. Logging code attenuation is something I would like to avoid if there is a better way to get more information where the Exception really occurred.

+3
3

, , - global.asax, :

    protected void Application_Error(object sender, EventArgs e)
    {
        Exception ex = Server.GetLastError();
        Log.WriteException(ex);   // this is your code
    }

- , , . , , , .

- , , web.config:

  <customErrors mode="On" defaultRedirect="error.html">
    <error statusCode="500" redirect="500.aspx"/>
    <error statusCode="404" redirect="404.aspx"/>
    <error statusCode="403" redirect="403.aspx"/>
  </customErrors> 

error.html , , , , " .

asp.net - , .

+3

- - , Log4Net ASP.NET ?

+1

Without cluttering my code with a log, I think the way to do this is to reorganize your code into smaller methods. It looks like you have a great method that does a lot of things, and an exception can occur in several places inside this method. This has happened to me before, and the way I narrowed it down is to break the method into smaller pieces. Since you can still see the names of the methods in the stack trace, more detailed methods will help you track where the exception is thrown.

0
source

Source: https://habr.com/ru/post/1704059/


All Articles