views:

465

answers:

7

Hi, how can I trace code execution of my C# application? Are there any tools available. Please Help. I have an issue in my production site.

Thanks in Advance

+1  A: 

Can you, in your code, write the debug information ( e.g, "now at method 1") to a log file?

You might find tools like log4net and PostSharp helpful.

Ngu Soon Hui
+1  A: 

You could use some external log library (such as Log4Net), or even use Visual Studio's ability to perform remote-debugging and step inside your code.

Shimrod
+5  A: 

There is a built in tool in visual studio called a debugger.

You set a breakpoint in your code and step through.

The .NET framework also provides tracing classes in the System.Diagnostics namespace.

For a running application that has no code support for tracing, you may be able to use a profiler (such as the redgate ANTZ profiler or the JetBrains dotTrace), but this will impact performance.

If you have a memory dump (either from a crash or an manually induced one), you can use windbg to analyse the dump. This will include trace information.

Oded
Ian
@Ian: My comment was not quite correct, so I removed it and upvoted intead (when I actually read the full answer)
Fredrik Mörk
+1 for mentioning the built-in trace logging support; I often find it to be overkill to bring in external logging libraries.
Fredrik Mörk
The OP mentioned that it's on the `production` site, a debugger is probably unavailable. Unless you are introducing him something like windbg?
Ngu Soon Hui
@Ngu Soon Hui - can you please expand on this. What other tools do you know that will allow tracing production code that was not coded with tracing and logging?
Oded
@Oded, I think the most you can use is windbg, it's only useful when the application crashes. For more detail analysis, you probably need to build the thing in, like you said, using tracing class.
Ngu Soon Hui
@Oded: I think that @Ngu is referring to the first two sentences in your answer (I got stuck at that as well to start with). Setting a breakpoint in the code and attaching a debugger is nothing that you can typically do in a *production* environment.
Fredrik Mörk
@Frederik Mörk - I was genuinely interested to know if there are any other options... And indeed those two sentences were the only ones when I first posted.
Oded
+3  A: 

There is also JetBrains dotTrace which is excellent.

Antony Koch
A: 

In Visual Studio 2005+ press F11 instead of F5 to run the application.

Or you can insert a breakpoint (clicking to the left of the line where you want to break so that VS shows a red dot).

Alxandr
A: 

Visual studio has great debugging tool however if that too terned out to be not sufficient then you can start with static code analysis tools which are helpful to analyze the code branches.

Anil Namde
A: 

To trace production Issues the best option is ETW tracing. Especially in ASP.NET there are built-in providers which can help identify the Perf Issues.

And if you are using Window2008 then the ETW traces can give call-stacks. There are ETW tracing from IIS, FileSystem , Registry , Threading and everything possible. Here is an MSDN article on this and to get Managed call-stacks I have few posts

Naveen