We have a "logger" class which have log method that get the log message, and wrote to the log the message and the calling method, first we did the following also to send to the log method new parameter Method.Base.GetCurrentMethod()
.
I found another way, to use Relection.MethodBase:
public void Log(string message)
{
stackTrace = new StackTrace();
string methodName = stackTrace.GetFrame(1).GetMethod().Name;
....
}
But I've a problem, that every calling for the log method, I forced to create new instance from StackTrace
, and when I trying to create the instance in the constructor, I get that the method name is InvokeMethod
.
We're using MEF in our project. Any ideas how to improve the code?