static string GetExceptionText(Exception ex, string strType) { // Exception ex = (Exception)e.Exception; string strError = "发生未捕获的" + strType + "异常: \r\n" + ExceptionUtil.GetDebugText(ex); Assembly myAssembly = Assembly.GetAssembly(typeof(Program)); strError += "\r\ndp2Circulation 版本: " + myAssembly.FullName; strError += "\r\n操作系统:" + Environment.OSVersion.ToString(); strError += "\r\n本机 MAC 地址: " + StringUtil.MakePathList(SerialCodeForm.GetMacAddress()); // TODO: 给出操作系统的一般信息 // MainForm main_form = Form.ActiveForm as MainForm; if (_mainForm != null) { try { _mainForm.WriteErrorLog(strError); } catch { WriteWindowsLog(strError, EventLogEntryType.Error); } } else { WriteWindowsLog(strError, EventLogEntryType.Error); } return(strError); }
static void CrashReport(string strText) { // MainForm main_form = Form.ActiveForm as MainForm; MessageBar _messageBar = null; _messageBar = new MessageBar(); _messageBar.TopMost = false; //_messageBar.BackColor = SystemColors.Info; //_messageBar.ForeColor = SystemColors.InfoText; _messageBar.Text = "dp2Circulation 出现异常"; _messageBar.MessageText = "正在向 dp2003.com 发送异常报告 ..."; _messageBar.StartPosition = FormStartPosition.CenterScreen; _messageBar.Show(_mainForm); _messageBar.Update(); int nRet = 0; string strError = ""; try { string strSender = ""; if (_mainForm != null) { strSender = _mainForm.GetCurrentUserName() + "@" + _mainForm.ServerUID; } // 崩溃报告 nRet = LibraryChannel.CrashReport( strSender, "dp2circulation", strText, out strError); } catch (Exception ex) { strError = "CrashReport() 过程出现异常: " + ExceptionUtil.GetDebugText(ex); nRet = -1; } finally { _messageBar.Close(); _messageBar = null; } if (nRet == -1) { strError = "向 dp2003.com 发送异常报告时出错,未能发送成功。详细情况: " + strError; MessageBox.Show(_mainForm, strError); // 写入错误日志 MainForm.WriteErrorLog(strError); #if NO if (_mainForm != null) { _mainForm.WriteErrorLog(strError); } else { WriteWindowsLog(strError, EventLogEntryType.Error); } #endif } }