Here is a simple tutorial for those who want to use the file name or the source code line that is running.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | using System; namespace GetFilenameORCurrentWorkingCS { class Program { static void Main(string[] args) { Console.WriteLine("Hello World!"); string thisFile = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName(); Console.WriteLine("current-working-cs-file name is : " + thisFile); int currentLine = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileLineNumber(); Console.WriteLine("current-working-cs-source-code is : " + currentLine); } } } |