user239635
user239635

Reputation: 301

How to trace code execution in C#

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

Upvotes: 3

Views: 8894

Answers (7)

Naveen
Naveen

Reputation: 4110

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

Upvotes: 0

Oded
Oded

Reputation: 498972

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.

Upvotes: 9

Anil Namde
Anil Namde

Reputation: 6608

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.

Upvotes: 0

Alxandr
Alxandr

Reputation: 12423

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).

Upvotes: 0

Antony Koch
Antony Koch

Reputation: 2053

There is also JetBrains dotTrace which is excellent.

Upvotes: 4

Shimrod
Shimrod

Reputation: 3205

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.

Upvotes: 1

Graviton
Graviton

Reputation: 83254

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.

Upvotes: 1

Related Questions