首页 > 解决方案 > 如何理解 Windows 日志信息?

问题描述

我写了自动启动的ac#windows服务,它的工作主要是删除一些文本文件和修改父文件夹的最后写入时间。当这个程序第一次完成这项工作时,这个服务意外地停止了。我检查系统的日志记录,但我无法从日志记录信息中定位错误代码。所以我需要你的帮助!非常感谢!

这些是异常信息,异常发生在 .NET 运行时:

System.IO.IOException
at System.IO.__Error.WinIOError(Int32, System.String)
at 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, Boolean, Boolean)
at System.IO.FileStream..ctor(System.String, System.IO.FileMode, System.IO.FileAccess, System.IO.FileShare, Int32, System.IO.FileOptions, System.String, Boolean, Boolean, Boolean)
at System.IO.StreamWriter.CreateFile(System.String, Boolean, Boolean)
at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding, Int32, Boolean)
at System.IO.StreamWriter..ctor(System.String, Boolean, System.Text.Encoding)
at System.IO.File.InternalAppendAllText(System.String, System.String, System.Text.Encoding)
at WindowsService1.Service1+<>c__DisplayClass5_0.<Rec>b__0()
at System.Threading.Tasks.Task.Execute()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(System.Threading.Tasks.Task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at WindowsService1.Service1+<Rec>d__5.MoveNext()
at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_1(System.Object)
at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

上述异常20秒后,出现另一个错误显示错误模块路径为C:\Windows\system32\KERNELBASE.dll

标签: windowslogging

解决方案


WindowsService1.Service1+<>c__DisplayClass5_0.b__0()
WindowsService1.Service1+d__5.MoveNext()

这两个堆栈条目实际上是您的应用程序的代码。顺便说一句,这就是为什么为项目指定非默认名称是一个好主意,如果您要命名它们,MyCompany.PreciousService您会注意到它们不是来自运行时。

您可能还没有编写这些<>c__DisplayClass5_0d__5嵌套类。C# 编译器做到了。这就是异步方法或 IEnumerable-returning 方法实现的幕后发生的事情yield return

理解转储的最简单方法——至少在调试版本中保持Service1.pdb一致。Service1.exe您需要同时构建它们,不能先构建 .exe 然后使用另一个构建中的 .pdb,不匹配。重现问题,您应该在堆栈跟踪中看到源文件名和行号。


推荐阅读