.NET Tip: Debugging: Dynamically Determining the Name of the Current Function Wisconsin

Are you tired of hard-coding function names in trace messages? Have you ever used cut and paste to copy a trace statement and forgot to change the function name? There'll be no more wild goose chases because of bad function names when you determine the function name dynamically.

Local Companies

Acumium
608 310 9700 x 522
5133 West Terrace Drive Suite 300
Madison, , WI
R.E. Coker and Associates, Inc.
262-723-8104
108 W Court St.
Elkhorn, WI
HarrisData
262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI
Visionary Computer Solutions
262-365-9430
PO Box 406
Grafton, WI
IFS
414-577-5191
12000 W. Park Place
Milwaukee, WI
Xorbix Technologies Inc.
414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
Wireless Direct
1.866.707.8498
BOX 71101
shorewood, WI
R S InfoCon, Inc.
262-898-7456
2320 Renaissance Blvd
Sturtevant, WI
J & J Electronics of Appleton Inc
(920) 739-1610
2518 N Richmond St
Appleton, WI
User Friendly Internet-Division of Profit by Web Inc
(920) 830-9356
2700 W College Ave
Appleton, WI


.NET Tip: Debugging: Dynamically Determining the Name of the Current Function

provided by: 
Originally published at Internet.com


Determining function names dynamically can simplify your debugging and trace logic as well as ensure that your trace messages match the actual code that generated them. All you have to do is wrap all your calls to Trace() with your own custom function. This utility function then can reference the stack frame to find the name of the function that called it. Here is the utility function: public static void TraceContext(string FormattedMessage) { Trace.WriteLine(string.Format(FormattedMessage, new System.Diagnostics.StackFrame(1).GetMethod().Name)); }

This function takes the message to output to Trace() and replaces the '{0}' in the message string with the name of the function that called TraceContext(). That is really all there is to it. To test the function, I created a form and added a button. In the button's click event, I call TraceContext() and call another function that also calls TraceContext(). Here is the sample code for calling TraceContext(): private void button1_Click(object sender, EventArgs e) { TraceContext("In event handler: {0}"); DynamicNameTest(); } private void DynamicNameTest() { TraceContext("In function: {0}"); }

Here is the trace output when the button is clicked: In event handler: button1_Click In function: DynamicNameTest

You now can have confidence in your trace output because you do not have any hard-coded function names in your messages.

About the Author

Jay Miller is a Software Engineer with Electronic Tracking Systems, a company dedicated to robbery prevention, apprehension, and recovery based in Carrollton, Texas. Jay has been working with .NET since the release of the first beta and is co-author of Learn Microsoft Visual Basic.Net In a Weekend. Jay can be reached via email at jmiller@sm-ets.com.

Author: Jay Miller

Read article at Internet.com site

Featured Local Company

Visionary Computer Solutions

262-365-9430
PO Box 406
Grafton, WI
http://www.visionarycomputersolutions.com

Visionary Computer Solutions specializes in providing computer solutions of all sizes for all businesses, including:

-Custom software development

-Maintenance and enhancement of existing software

-Web development

-PC hardware upgrades

Your business is extremely important to you. And your business success is extremely important to us. We work closely with our clients to determine their needs and provide advanced solutions on-time and within their budget.

Headquartered in Grafton, Wisconsin, we work with businesses throughout the United States.


Related Articles
- Improving Visual C++ Debugging with Better Data Display Wisconsin
Code is run in a debugger for two main reasons: examining the branches of code that are being executed, and examining data values to determine why the code is behaving in a certain manner. Inspecting data values can be significantly improved by customizing the debug information. See how that can be done in the Visual C++ debugger.
- ASP.NET Tip: Using RadioButton Controls in a Repeater Wisconsin
- ASP.NET Tip: Adding Tracing to an Application Wisconsin
- Whammy Tracing: Hassle-Free .NET Debugging Wisconsin
- .NET Tip: Filling Lists with Enums Wisconsin
- Catch C/C++ Errors Early with VSTS Code Verifier Wisconsin
- .NET Tip: Display All Fields and Properties of an Object Wisconsin
Regional Articles
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Appleton WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Baraboo WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Beaver Dam WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Beloit WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Brookfield WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Burlington WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Cedarburg WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Chippewa Falls WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Cudahy WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function De Pere WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Delavan WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Eau Claire WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Elkhorn WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Fond Du Lac WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Fort Atkinson WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Franklin WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Green Bay WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Hartland WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Janesville WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Kaukauna WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Kenosha WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function La Crosse WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Lake Geneva WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Manitowoc WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Marinette WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Marshfield WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Menasha WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Menomonee Falls WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Menomonie WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Merrill WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Middleton WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Milwaukee WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Mosinee WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Mukwonago WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Muskego WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Neenah WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function New Berlin WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Oak Creek WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Oconomowoc WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Onalaska WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Oshkosh WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Pewaukee WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Racine WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Rhinelander WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Rice Lake WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function River Falls WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Schofield WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Shawano WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Sheboygan WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function South Milwaukee WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Stevens Point WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Sturgeon Bay WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Sun Prairie WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Superior WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Thiensville WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Two Rivers WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Watertown WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Waukesha WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Waupaca WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Wausau WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function West Bend WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Whitewater WI
- .NET Tip: Debugging: Dynamically Determining the Name of the Current Function Wisconsin Rapids WI
Related Local Events
2008 Early Stage Symposium
Dates: 11/5/2008 - 11/6/2008
Location: Monona Terrace
Madison WI
View Details

Wisconsin Entrepreneurs' Conference
Dates: 6/9/2008 - 6/10/2008
Location: Hyatt Regency Hotel
Milwaukee WI
View Details
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Industrial Goods & Services Software
Business Services Family Insurance Technology
Career Financial Services Internet Telecommunications
Cars Food & Beverage Legal Transportation & Logistics
Computer Hardware Health Real Estate Travel
Construction Home Services Retail & Consumer Services Wedding
Education