473,326 Members | 2,090 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 1419
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Trace User | last post by:
Hello, I have a design question regarding Tracing and Trace Switches. I understand that Trace Switches can be configured through an application's .config file. When a switch is instantiated,...
0
by: Jay Pondy | last post by:
While logging or tracing an application I frequently need to know where the code is executing - the class.method name. One way to obtain this information is: Me.GetType.Name & "." &...
5
by: Stig | last post by:
I would like to output the sequence of method calls from a running c# applcaition, but I don't want to add Debug.trace calls at the entry and exit points in each an every methods. Does there...
0
by: Jay Pondy | last post by:
While logging or tracing an application I frequently need to know where the code is executing - the class.method name. One way to obtain this information is: Me.GetType.Name & "." &...
6
by: TPI | last post by:
I wrote application wich i working on IntPtr. Whole thing is using Marshal.ReadInt32 and Marshal.WriteInt32. And sometimes the application shuts down with out any wornings and exceptions. With...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.