When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod(), but
System.Reflection.MethodBase.GetCurrentMethod()
In C# 5 you can get that information using caller info:
//using System.Runtime.CompilerServices; public void SendError(string Message, [CallerMemberName] string callerName = "") { Console.WriteLine(callerName + "called me."); }
You can also get the [CallerFilePath] and [CallerLineNumber].
[CallerFilePath]
[CallerLineNumber]