We log our processes for debugging purposes, and use reflection to get the method name for logging. Currently, I call the logging method with a parameter of System.Reflection.MethodInfo, and inside the logging method it parses that parameter to use Method.DeclaringType.Name to get the name of the class the method lives in (and also Method.Name, which isn’t an issue at the moment). What I get from this is the ancestor name, and I want the descendant (even though the method being used is not overridden and is run directly from the ancestor). Is this possible? I went scrounging through the reflection information but didn’t find the descendant name anywhere.
I am not concerned about the performance issues of Reflection, and I’m willing to add additional parameters to the logger method if necessary to get the information I need.
Thanks!
No, you’re not going to get that from the
MethodInfo. You should pass inthis, at which point the logging code can callGetType()to find the actual type of the object.