Use the class StackFrame
.
sf.GetFileName(), sf.GetMethod(), sf.GetFileLineNumber()
If there’s a way release this information will not be available. There are techniques that can help, but in general are not worth, almost always only use this thrashing.
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 put in the Github for future reference.
Where to call this method is what will be shown. See the documentation.
There must be other techniques.
You can get the class name using
this.GetType().Name
and the method name usingMethodBase.GetCurrentMethod().Name
at least this information you can get in release.– Zorkind