I have a main method, ExecuteMethod, in C# which is in charge of executing the method passed as a parameter. Now I would like to make a log to a file in order to know which method is being executed every time (I am only interested in getting the method name):
public static void ExecuteMethod(Action myMethod)
{
ExecuteMethod(() => { myMethod(); return true; });
}
public static object ExecuteMethod(Func<object> myMethod)
{
string myMethodName = <method_name>; // How to extract method name here from myMethod parameter?
MyLog.Write("Calling to " + myMethodName);
// more stuff here
}
So for example, in my program I have calls like below:
public void m1()
{
ExecuteMethod(() => myCore.SomeMethod1(param1, param2));
}
public void m2()
{
ExecuteMethod(() => myCore.SomeMethod2(param1, param2, null));
}
Then from above ExecuteMethod, I would like to obtain the names of these methods passed as parameter which would be SomeMethod1 and SomeMethod2 in this case. How can I achieve this?