all groups > visual studio .net debugging > september 2006 >
You're in the

visual studio .net debugging

group:

simple tracing solution needed


simple tracing solution needed semedao
9/13/2006 6:31:56 PM
visual studio .net debugging:
Hi,
If you look at the example of using the Trace , you will see:
static int Main(string[] args)
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.AutoFlush = true;
Trace.Indent();
Trace.WriteLine("Entering Main");
Console.WriteLine("Hello World.");
Trace.WriteLine("Exiting Main");
Trace.Unindent();
return 0;
}


The Trace.WriteLine receive string param , however , I want to use some
"trace" that will show me the mehod or , call stack , that it enter in , if
we take the above example , I would like:

static int Main(string[] args)
{
Trace.Listeners.Add(new TextWriterTraceListener(Console.Out));
Trace.AutoFlush = true;
Trace.Indent();
Trace.WriteLine(?); -> will output "appname.Main , line # 123...."

Or

Trace.WriteLineCurrent(); -> will output "appname.Main , line # 123...."
return 0;
}

somebody knows about such solution to avoid har coding the method names ?

Or maybe , some call that automaticly will trace every begining of method
even we did not call WriteLine()

something like:

Trace.StartTrace()

methodA()

methodB()

methodC()

Trace.StopTrace()



the output will show:

enter A()

exit A()

enter B()

exit B()

enter C()

exit C()

Re: simple tracing solution needed semedao
9/14/2006 12:00:00 AM
thanks
I will use the Environment solution
[quoted text, click to view]

RE: simple tracing solution needed jetan NO[at]SPAM online.microsoft.com (
9/14/2006 8:01:38 AM
Hi Semedao,

Trace class is designed as a utility class to help us write tracing
information to the customized pipe. However, it does contains the power of
stack walking or method tracing.

Net provided StackTrace&StackFrame classes for us to do the stack walking
work. Also you may use Reflection API, MethodInfo.GetCurrentMethod or
MethodBase.GetCurrentMethod static methods to get the current executing
method. Please refer to the article below for more information about the
customize usage of these classes:
"TraceListeners and Reflection"
http://www.codeproject.com/csharp/customtracelistener.asp

However, if you just want to get the stack trace of the current execting
code, my experience told me that the simplest way is using
System.Environment.StackTrace proeprty. This property internally
encapsulate StackTrace&StackFrame classes to get the stack. You may give it
a try.

Finally, there is no build-in support for tracing method calling in .Net.
This is because tracing each methods will have a lot influence over
performance. If you really want to get trace function in .Net code, we may
use .Net Profiling API to get this done. The Profiling API provides a lot
of hooking notifications for us, in which the method entry and exit
notifcation is what we are interested in. You may leverage this
notification to implement a trace library on your own. Please refer to the
2 articles below for more information about method entry and exit
notification in .Net Profiling API:
"Receiving Method Entry and Exit Notifications" section in "The .NET
Profiling API and the DNProfiler Tool"
http://msdn.microsoft.com/msdnmag/issues/01/12/hood/
"Using the Profiling API Enter/Leave Function Hooks "
http://blogs.msdn.com/jkeljo/archive/2005/08/11/450506.aspx

Additionally, John Robbins uses .Net Profiling API to create a managed
exception monitor library in "Chapter 10: Managed Exception Monitoring" of
his wonderful book "Debugging Applications for Microsoft .NET and Microsoft
Windows".

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: simple tracing solution needed jetan NO[at]SPAM online.microsoft.com (
9/18/2006 2:11:43 AM
Hi Semedao,

Glad to see my reply makes sense to you.

Yes, you may give the Environment.StackTrace approach a try. What's about
the method tracing? Do you take the .Net Profiling API approach? If you
have anything concern or need any help, please feel free to tell me. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Re: simple tracing solution needed jetan NO[at]SPAM online.microsoft.com (
9/20/2006 3:45:59 AM
Hi Semedao,

How about this issue? Is your problem resolved? If you still need any help
or have any concern, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
AddThis Social Bookmark Button