Is there a function that returns the current class/method name? [duplicate]

Solution 1:

Current class name:

this.GetType().Name;

Current method name:

using System.Reflection;

// ...

MethodBase.GetCurrentMethod().Name;

Since you're using this for logging purposes, you may also be interested in getting the current stack trace.

Solution 2:

System.Reflection.MethodBase.GetCurrentMethod()

Solution 3:

System.Reflection.MethodBase.GetCurrentMethod().DeclaringType