How To: Obtain Method Name Programmatically For Tracing
I am not a fan of hard-coding method names in exception or trace messages. Here is a utility method to allow access to method name at runtime:
public static void TraceContext(string messageFormat) { Trace.WriteLine(string.Format(messageFormat, new System.Diagnostics.StackFrame(1).GetMethod().Name)); }
If I call the method above from inside another method:
protected void Application_AuthorizeRequest(object sender, EventArgs e) { Tools.TraceContext("Inside of {0} event handler"); }
"Inside of Application_AuthorizeRequest event handler"
Posted on Sunday, July 8, 2007 at 07:28PM
by
J. Michael Palermo IV
in asp.net, code
|
Post a Comment
|
1 Reference
References (1)
References allow you to track sources for this article, as well as articles that were written in response to this article.
-
Response: Tracing in ASP.NET Application ClassesI'm a big fan of tracing in .NET and use it in every project I work on since it's a great way to find

Reader Comments