471,627 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Application Method Tracing

I have inherited an application that I am not very familiar with and I would
like to know if there is a way to produce a trace of what methods were
called and the order in which they executed for particilar instances.
Nothing fancy just something that would maybe log each method to a file as
it executes.

Thanks,

Matt

Jan 4 '06 #1
2 1379
Hi Matt,

What do you actually mean by "for particular instances"? - are you referring
to specific objects?

AFAIK, there is no direct way to log each method as it executes. So in other
words, you will have to add a code statement in each method to log it.

However, you could make use of the stack trace to walk back and find out
which methods were executed. You need to use the StackTrace.GetFrame method
for that. Check out http://rakeshrajan.com/blog/archive/2005/05/02/16.aspx
for an example.

--
HTH,
Rakesh Rajan
MVP, MCSD
http://www.rakeshrajan.com/
"Matt" wrote:
I have inherited an application that I am not very familiar with and I would
like to know if there is a way to produce a trace of what methods were
called and the order in which they executed for particilar instances.
Nothing fancy just something that would maybe log each method to a file as
it executes.

Thanks,

Matt

Jan 5 '06 #2
Matt,

If you are willing to place a line of code in each method, see the Debug or
Trace classes in the System.Diagnostics namespace. Also, take a look at the
System.Diagnostics.TextWriterTraceListener class, which can be used by
either the Debug or Trace classes to dump the trace to a file as the program
executes.

Here is an example for the help file:
public static int Main(string[] args)
{
// Create a file for output named TestFile.txt.
Stream myFile = File.Create("TestFile.txt");

/* Create a new text writer using the output stream, and add it to
* the trace listeners. */
TextWriterTraceListener myTextListener = new
TextWriterTraceListener(myFile);
Trace.Listeners.Add(myTextListener);

/* Create a text writer that writes to the console screen, and add
* it to the trace listeners */
TextWriterTraceListener myWriter = new
TextWriterTraceListener(System.Console.Out);
Trace.Listeners.Add(myWriter);

// Write output to the file and to the console screen.
Trace.Write("Test output ");

// Write only to the console screen.
myWriter.WriteLine("Write only to the console screen.");

// Flush and close the output.
Trace.Flush();
myWriter.Flush();
myWriter.Close();

return 0;
}
Hope this helps,
Dave
Jan 5 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Jay Pondy | last post: by
reply views Thread by Jay Pondy | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.