I have a requirement where I need to know the name of the class (ApiController) which has a method (GetMethod) which is called by another m
using System.Diagnostics;
var className = new StackFrame(1).GetMethod().DeclaringType.Name;
Goes to the previous level of the Stack, finds the method, and gets the type from the method. This avoids you needing to create a full StackTrace, which is expensive.
You could use FullName if you want the fully qualified class name.
Edit: fringe cases (to highlight the issues raised in comments below)
async methods get compiled into a state machine, so again, you may not get what you expect. (Credit: Phil K)