Use the class StackFrame
. .
sf.GetFileName(), sf.GetMethod(), sf.GetFileLineNumber()
If you are in a release mode this information will not be available. There are techniques that can help, but they are usually not worth it, you should almost always only use debugging .
You can also create a method like this:
public static void MostraMetodo([CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) {
WriteLine($"File: {sourceFilePath}, Method {caller}, Line: {lineNumber} ");
}
I placed GitHub for future reference.
Where to call this method is what will be shown. See documentation .
You should have other techniques.