I changed the above example a little into this piece of working example code:
public class MethodLogger : IDisposable
{
public MethodLogger(MethodBase methodBase)
{
m_methodName = methodBase.DeclaringType.Name + "." + methodBase.Name;
Console.WriteLine("{0} enter", m_methodName);
}
public void Dispose()
{
Console.WriteLine("{0} leave", m_methodName);
}
private string m_methodName;
}
class Program
{
void FooBar()
{
using (new MethodLogger(MethodBase.GetCurrentMethod()))
{
// Write your stuff here
}
}
}
Output:
Program.FooBar enter
Program.FooBar leave