- Home /
How to get the linenumber from a stackframe?
Hello, i want to trace what my app is doing.
so i made a short debug logger
Code (CSharp):
static public void prinstantiate(params string[] mytuf) {
if (!tmpflowlog) return;
System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(); // get call stack
System.Diagnostics.StackFrame[] stackFrames = stackTrace.GetFrames(); // get method calls (frames)
// write call stack method names
string display="";
foreach (string mtuf in mytuf) {
display += mtuf;
}
string text= "\n Instantiate: " + display + " Count: "+ profiler +" on " + g.stopWatch.Elapsed+" \n";
foreach (System.Diagnostics.StackFrame stackFrame in stackFrames) {
text+= " " + stackFrame.GetMethod ().Name+ " L" +stackFrame.GetFileLineNumber() + " : ";
}
File.AppendAllText (Path.Combine (p.logpath, "instantiate.txt"), text);
//Debug.Log (text);
profiler++;
}
but i cannot get the lines with it prints something like:
Instantiate: infoinput Count: 1825 on 00:00:10.4046821 prinstantiate L0 : getobjbn L0 : .cctor L0 : hover L0 : hover L0 : hover L0 : Update L0 :
Question 1: How can i get the linenumber?
Question2: Why does it return 0?
Answer by LiloE · Feb 22, 2017 at 08:21 AM
You forgot a parameter to the c'tor :-)
System.Diagnostics.StackTrace stackTrace = new System.Diagnostics.StackTrace(true);
The optional boolean parameter specifies that we want to gather source related info such as file names and line numbers.
It is false by default.
It doesn't work on Android and iOS device. Why I don't know can some one help me.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Disable hashing of function names in unity build 1 Answer
Unloading Broken Assembly | How to solve this !? 2 Answers
EventTrigger PointerEnter 1 Answer