Created
August 10, 2017 10:04
-
-
Save bozhink/0b6159bd1767aae2aeb9e432ca39704c to your computer and use it in GitHub Desktop.
Get calling mathod name C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class Helpers | |
{ | |
internal string GetCallingMethodName() | |
{ | |
string result = "unknown"; | |
StackTrace trace = new StackTrace(false); | |
for (int i = 0; i < trace.FrameCount; i++) | |
{ | |
StackFrame frame = trace.GetFrame(i); | |
MethodBase method = frame.GetMethod(); | |
Type dt = method.DeclaringType; | |
if (!typeof(ILogger).IsAssignableFrom(dt) && method.DeclaringType.Namespace != "DiagnosticsLibrary") | |
{ | |
result = string.Concat(method.DeclaringType.FullName, ".", method.Name); | |
break; | |
} | |
} | |
return result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment