【发布时间】:2020-08-04 07:00:23
【问题描述】:
我在我的 C# WinForms 项目中设置了一个日志系统,用于写入日志 txt 文件。典型的错误消息如下所示:
Error :
8:34:48 AM Tuesday, April 21, 2020
:
:System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
at System.Collections.ArrayList.get_Item(Int32 index)
at System.Windows.Forms.DataGridViewColumnCollection.get_Item(Int32 index)
at CrossReferenceTool.frmXRefTool.DefineControlsLayout() in <PathToSourceCsFile>:line 306
有什么方法可以获取该错误消息的一部分吗?具体来说,我想提取违规方法(在本例中为DefineControlsLayout())和行号。
【问题讨论】:
-
这是在调试器中看到的标准异常消息吗?
-
@ChrisBD,我从
catch (Exception ex)收到错误文本,只是将es.ToString()发送到日志文件。
标签: c# winforms error-handling error-logging