【发布时间】:2011-06-02 19:54:48
【问题描述】:
我维护一个应用程序,当应用程序发生错误时会向我发送电子邮件。我将堆栈跟踪转储到电子邮件中,它似乎工作正常。唯一缺少的是变量的值。我接到所有的电话等等,从来没有任何变量。为了将这些变量值也转储到电子邮件中,我还缺少什么?
以下是我用来将其转储到电子邮件中的代码:
UtilityClass.SendEmail(shortNTID,
"admin@mydomain.com",
new string[] { "support@mydomain.com" },
"MyApplication error has occured for user: " +
shortNTID + " (Main).",
"Message: " + ex.Message.ToString() +
" Source: " + ex.Source.ToString() +
" Target Site: " + ex.TargetSite.ToString() +
" Stack Trace: " + ex.StackTrace.ToString());
这是电子邮件中的结果:
消息:指定的转换无效。来源:MyApplication 目标站点:Void FindFormAndActivate(MyApplication.MDIParentForm, System.String, System.Object) 堆栈跟踪:在 MyApplication.UtilityClass.FindFormAndActivate(MDIParentForm frmMDIParentForm, String formName, Object 参数) 在 MyApplication.DashboardAlerts.NavigateToAssignment() 在 MyApplication.DashboardAlerts.utAlerts_MouseClick(对象发送者,MouseEventArgs e) 在 System.Windows.Forms.Control.OnMouseClick (MouseEventArgs e) 在 System.Windows.Forms.Control.WmMouseUp(消息和 m,MouseButtons 按钮,Int32 点击) 在 System.Windows.Forms.Control.WndProc(消息和 m) 在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(消息& m) 在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(消息和 m) 在 System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
编辑
一些答案建议我自己将变量值添加到电子邮件中。我将如何获得这些值?发送电子邮件的这个 sn-p 代码不在失败的方法中。这是在发生异常时运行的代码。如果异常没有得到处理和纠正,我让它冒泡到线程的顶部,就像Application.ThreadException += new ThreadExceptionEventHandler(HandleError); 和HandleError 方法是进行此电子邮件调用的方法。它不知道导致异常的方法的变量或参数是什么。
【问题讨论】:
标签: c# .net variables stack-trace