简体   繁体   English

如何查看.NET应用程序的堆栈跟踪

[英]How to see the stacktrace of a .NET application

I have a .NET Windows application in the production that has no access to Visual Studio (standard edition), and the only thing they can install is the Express edition, which does not have the Just-In-Time Debugging option (the one which has the debug button when it crashes). 我在生产中有一个.NET Windows应用程序无法访问Visual Studio(标准版),他们唯一可以安装的是Express版本,它没有Just-In-Time Debugging选项(崩溃时有调试按钮)。 So I was just wondering if there is a Windows application debugging tool or something else that I can run or attach to see stacktraces. 所以我只是想知道是否有一个Windows应用程序调试工具或其他我可以运行或附加的东西来查看stacktraces。 I also enabled PDB in my application, but it does not provide any more information, so I can trace my crashes (caused by unhandled exceptions). 我还在我的应用程序中启用了PDB ,但它不提供任何更多信息,因此我可以跟踪我的崩溃(由未处理的异常引起)。

If you are catching exceptions, the Exception object contains the stack trace: Exception.StackTrace . 如果要捕获异常,则Exception对象包含堆栈跟踪: Exception.StackTrace Also, you have access to it with Environment.StackTrace . 此外,您可以使用Environment.StackTrace访问它。

In the code below there is also an event handler for unhandled exceptions which will write the exception, including the stack trace, to the event log. 在下面的代码中,还有一个未处理异常的事件处理程序,它将异常(包括堆栈跟踪)写入事件日志。

// Sample for the Environment.StackTrace property
using System;

class Sample
{
    public static void Main()
    {
        AppDomain.CurrentDomain.UnhandledException += 
          new UnhandledExceptionEventHandler(UnhandledExceptions);

        Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace);
        throw new Exception("Fatal Error");
    }

    static void UnhandledExceptions(object sender, UnhandledExceptionEventArgs e)
    {
        string source = "SOTest";
        if (!System.Diagnostics.EventLog.SourceExists(source))
        {
            System.Diagnostics.EventLog.CreateEventSource(source, "Application");
        }

        System.Diagnostics.EventLog log = new System.Diagnostics.EventLog();
        log.Source = source;

        log.WriteEntry(e.ExceptionObject.ToString(), 
                       System.Diagnostics.EventLogEntryType.Error);
    }

您还可以使用windbg和sos.dll

您可以尝试CLR Profiler

The stacktraces of .NET application exceptions are logged in your Event Viewer under Applications. .NET应用程序异常的堆栈跟踪记录在“应用程序”下的“事件查看器”中。

This link throws a 404: 此链接抛出404:

alt text http://eduncan911.com/blog/thumbnail/exception-in-iis-stackoverflow-logs.png alt text http://eduncan911.com/blog/thumbnail/exception-in-iis-stackoverflow-logs.png

也许EQATEC Tracer可以帮助你。

Use: 采用:

.NET Framework 2.0 SDK ships with Microsoft CLR Debugger. .NET Framework 2.0 SDK附带Microsoft CLR调试器。 It works similar to Visual Studio debugger (though source files are readonly), so you can give it a try. 它的工作方式类似于Visual Studio调试器(尽管源文件是只读的),因此您可以尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM