When logging in C#, how can I learn the name of the method that called the current method? I know all about System.Reflection.MethodBase.GetCurrentMethod()
, but I want to go one step beneath this in the stack trace. I've considered parsing the stack trace, but I am hoping to find a cleaner more explicit way, something like Assembly.GetCallingAssembly()
but for methods.
C# – How to find the method that called the current method
cloggingnetstack-tracesystem.diagnostics
Related Topic
- C# – How to use reflection to call a generic method
- Java – How to get the current stack trace in Java
- Java – How to convert a stack trace to a string
- C# – How to generate random alphanumeric strings
- C# – How to remedy “The breakpoint will not currently be hit. No symbols have been loaded for this document.” warning
- Python – Get exception description and stack trace which caused an exception, all as a string
- C# – How to run an async Task
method synchronously - Scala: list.flatten: no implicit argument matching parameter type (Any) = > Iterable[Any] was found
Best Answer
Try this:
one-liner:
It is from Get Calling Method using Reflection [C#].