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.
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.
There is also JetBrains dotTrace which is excellent.
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.
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.
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).
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.
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
精彩评论