2
votes
EnterMethod/LeaveMethod - Remove the method name from the parameters by usage of CallerMemberName attribute
It is not necessary anymore to specify the method name on every call to EnterMethod/LeaveMethod.
The CallerMemberName attribute provides the name of the calling method automatically.
Try the snippet below.
void Main()
{
MethodNameToBeLogged();
}
public void MethodNameToBeLogged()
{
EnterMethod();
LeaveMethod();
}
public void EnterMethod([CallerMemberName] string memberName = "")
{
Console.WriteLine($"Entering method '{memberName}'");
}
public void LeaveMethod([CallerMemberName] string memberName = "")
{
Console.WriteLine($"Leaving method '{memberName}'");
}
