【问题标题】:Best way to track Windows Service Unhandled Exception跟踪 Windows 服务未处理异常的最佳方法
【发布时间】:2022-01-21 22:20:02
【问题描述】:

我有一个 Windows 服务应用程序。该服务基本上是在特定时间将 Excel 文件复制到目录,然后读取 Excel 行,最后根据它读取的行中的数据更新 SQL Server 表。

最近,它有时会崩溃。在查看日志时,我发现它崩溃了,因为:

应用程序:WinCCServiceIzmit.exe 框架版本:v4.0.30319 说明:进程因未处理的异常而终止。

异常信息:System.IO.IOException

在 System.IO.__Error.WinIOError(Int32, System.String)
在 System.IO.FileStream.Init(System.String, System.IO.FileMode, System.IO.FileAccess, Int32, Boolean, System.IO.FileShare, Int32, System.IO.FileOptions, SECURITY_ATTRIBUTES, System.String, Boolean , 布尔值, 布尔值)
在 System.IO.FileStream..ctor(System.String,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,Int32,System.IO.FileOptions,System.String,布尔值,布尔值,布尔值)
在 System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)
在 System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)
在 System.IO.StreamWriter..ctor(System.String, Boolean)
在 System.IO.File.AppendText(System.String)
在 WinccService.InnerOperation.WriteToFile(System.String)
在 WinccService.InnerOperation.Stop()
在 WinccService.WinccIzmit.start()
在 System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
在 System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
在 System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
在 System.Threading.ThreadHelper.ThreadStart()

你们知道如何跟踪问题的根源吗?应用程序的代码行太多。

谢谢。

【问题讨论】:

    标签: c# windows-services


    【解决方案1】:

    订阅UnhandeledException Event 或将服务中的最高级别(可能在您从OnStart 开始的方法中)包装到try-catch 中。

    通过这种方式,您可以捕获异常并将更多详细信息写入单独的日志文件以了解发生了什么。

    尽管如此,检查您的堆栈似乎错误发生在WinccService.InnerOperation.WriteToFile() 中,将从WinccService.InnerOperation.Stop() 调用。因此,研究这两种方法以及谁调用它们应该可以帮助您找到问题所在。此外,此时似乎将调用 System.IO.StreamWriter.CreateFile() 并失败。可能的原因可能是文件名无效、文件已存在或权限问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-06-23
      • 2010-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-08
      • 2021-06-16
      相关资源
      最近更新 更多