【问题标题】:Released .NET Program Crashing发布 .NET 程序崩溃
【发布时间】:2016-04-29 15:44:58
【问题描述】:

我有一个已完成并在客户计算机上运行的 .NET 应用程序。我收到报告说它偶尔会因 Windows 错误框而崩溃

xxx程序停止工作,一个问题导致程序停止正常工作。如果有可用的解决方案,Windows 将关闭该程序并通知您。

我正在尝试跟踪此问题的根源。我认为这是某处未处理的异常,但我很难找到位置。我正在寻找有关跟踪源的帮助的输入。尽管该程序是 .NET,但我使用了一些非托管资源,例如 OPC 和我编写的一个小包装器,但我觉得我很好地涵盖了编组。该应用程序几乎 24/7 运行,目前它可能每 4-10 天崩溃一次。

我正在考虑的一件事是订阅AppDomain.UnhandledExceptionEventHandler 并将堆栈跟踪记录到文件中。这可能吗?如何去做?

谢谢

【问题讨论】:

  • 不是程序化解决方案,而是来自其他疑难解答者的评论——很多时候,由于应用程序意外终止,Windows 事件查看器中会记录一些相关内容,例如特定的堆栈跟踪。

标签: c# exception crash


【解决方案1】:

我会创建一个日志系统。即使它只是从页面中获取基本错误的尝试。我之前使用下面的代码在服务器上存储日志文件。

public void logError(string errorString)
{
     try
     {
         // Takes unknown errors and logs them to the log file 
         string user = HttpContext.Current.User.Identity.Name.ToString();
         string FileLine = user + ", " + DateTime.Now.ToString() + ", " + errorString;
         string filename = HttpContext.Current.Server.MapPath("../Log/error_log.txt");

         using (System.IO.StreamWriter file = new System.IO.StreamWriter(filename, true))
         {
             file.WriteLine(FileLine);
             file.WriteLine("---------------------------------------");
         }
     }
     catch (Exception ex)
     {
        // send email, or another notification 
     }

}

你可以这样称呼它:

try
{
   //function code
}
catch (Exception ex)
{                                                                                
   logError(ex.ToString());
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 1970-01-01
    • 2011-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    相关资源
    最近更新 更多