I am trying to write the line number and frame to a text file, but I cannot get it to work. From what I read online as I wrote, this should work, but in fact it does not output line numbers, which makes my debugging quite difficult. Can someone help, possibly pointing out where my code might be wrong?
catch (Exception e)
{
var st = new StackTrace(e, true);
var frame = st.GetFrame(0);
var line = frame.GetFileLineNumber();
var sw = new System.IO.StreamWriter(filename, true);
sw.WriteLine(
DateTime.Now.ToString() + "\r\n"
+ e.Message + "\r\n"
+ e.InnerException + "\r\n"
+ e.Source + "\r\n"
+ frame + "\r\n"
+ line);
sw.Close();
}
It displays some information, not line / frame numbers.
Here is an example of getting the result.
22/08/2016 08:34:24
Input string was not in a correct format.
StringToNumber at offset 12099653 in file:line:column <filename unknown>:0:0 0
Also note that the application runs in Debug not Release.
source
share