locked
How to get current line number and the filename?

    Question

  • Hello,

    How to get Current linenumber and filename so that I can print using Debug.WriteLine.

    Thanks in advance.

    Monday, April 21, 2014 7:11 AM

All replies

  • see this related thread

    hope this helps!

    Monday, April 21, 2014 7:53 AM
  • Hi Shreeharsh,

    Thanks for the reply, but there is no StackTrace class inside System.Diagnostics.

    Below code works but is there any other way, I don't want to call method as when Project is compiled as release mode the debug.writeline gets removed, but with method my programs still calls this log method with no line to execute in release mode.

    private static void Log(string text,
                           
    [CallerFilePath] string file = "",
                           
    [CallerMemberName] string member = "",
                           
    [CallerLineNumber] int line = 0)
    {
       
    Debug.WriteLine("{0}_{1}({2}): {3}", Path.GetFileName(file), member, line, text);
    }


    • Edited by zee_patel Monday, April 21, 2014 9:16 AM
    Monday, April 21, 2014 8:54 AM