Stack trace

relative to the stack trace depth in debug and release mode. I came to the following conclusion (by calling exception.ToString ()):

in debug mode, you get a full stack trace with line numbers (several frames) in release mode, instead of a full stack trace, you get only a throw method in a try block (single frame) with line numbers

  • It's true? Is there a way to get the full stack in release mode?

Hello,

I want to log exception details. The log should include the entire stack trace (all methods in the chain) log shoud include the line numbers of each method in the stack trace.

I am trying to use two methods in debug and release mode. I did not like the results:

in debug mode, both return a full stack trace with line numbers :-) in release mode, both returned only catch method data. one cannot really know which call in the try block failed

Can anyone explain this? also is excepyion stack trace information lost when referring to an exception from another method called in a catch block

thank

option1: exception.ToString-

option2: same results (see below)

        calling static method receving  the exception as parameter 
        System.Diagnostics.StackTrace exceptionStackTrace = 
            new System.Diagnostics.StackTrace(e, true);
        System.Diagnostics.StackFrame [] exceptionStackFrames = 
            exceptionStackTrace.GetFrames();
         foreach (System.Diagnostics.StackFrame stackFrame in exceptionStackFrames)
        {
            message += String.Format("at {0} {1} line {2} column {3} \n",
                stackFrame.GetFileName() == null ? string.Empty : stackFrame.GetFileName(),
                stackFrame.GetMethod().ToString(),
                stackFrame.GetFileLineNumber(),
                stackFrame.GetFileColumnNumber());  
        }
+3
source share
1 answer

A debug build contains much more information than a build build of releases to make debugging easier, including things like line numbers.

This information is in the file pdb- if you do not include them in the released application, you cannot get line numbers in the stack trace.

this SO, .

+1

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


All Articles