Enter/Leave debug methods?
-
Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.
-
Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.
-
Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.
Hi, Something like this should do the trick;
System.Diagnostics.Debug.WriteLine(
new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Name);or, if you wanted to put this in a utility funtion;
public static string GetCurrentMethodName()
{
// Aight, not the current one, but we're actually interested in the
// name of the name of the previous method (0+1 in the list)
return new System.Diagnostics.StackTrace().GetFrame(1).GetMethod().Name;
}You've already looked at log4net? I found it to be a real help, combined with OneNote :)
I are Troll :suss:
-
Are there any methods available in Diagnostics or other class that will output the function name when it is entered/left? I need to trace execution through some spaghetti code I've inherited, and I'm hoping to avoid hand-coding enter/leave WriteLines.
You might find Spring.NET's AOP support useful. I've used the Java equivalent, but not the .NET version. It allows you to instrument existing code to add functionality such as you describe, without having to change the existing source. I don't really like AOP but it can be useful for situations like this.