Is there anyway to get the current method name from inside an async function?
I\'ve tried:
System.Reflection.MethodInfo.GetCurrentMethod();
>
It's a bit late to answer your question I guess but since I had the same issue and I needed to figure it out on my own due to lack of a good resolution to this on the internet, here is what I did and it works perfectly at least for me -
Regex somewhere that can be accessed by all callers since Regex objects need to be parsed before using them; hence, it can be expensive, and it's not a good practice to create them over and over if we can use the same one.public static readonly Regex ASYNC_METHOD_NAME_FORMAT = new Regex(@"^\<(?\w+)>\w+?");string methodName = ASYNC_METHOD_NAME_FORMAT.Match(MethodBase.GetCurrentMethod().ReflectedType.Name).Groups["method_name"].ValueI hope this helps!