示例#1
0
        /// <summary>
        /// 将系统异常信息记录到xml文件中
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        private static int InsertSystemToXml(CExceptionDecoraterBase_WuQi de)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement  xe  = null;

            try
            {
                doc.Load(CExceptionContainer_WuQi.s_xmlfilepath);
                XmlNode root = doc.SelectSingleNode("exceptions");
                if (null == root)
                {
                    return(0);
                }
                xe = doc.CreateElement("exception");
                xe.SetAttribute("type", "systemexception");

                XmlElement xetime = doc.CreateElement("time");
                xetime.InnerText = de.ExceptionInfo.d_time.ToString().Trim();
                xe.AppendChild(xetime);

                XmlElement xefullname = doc.CreateElement("fullname");
                xefullname.InnerText = de.ExceptionInfo.s_fullname;
                xe.AppendChild(xefullname);

                XmlElement xebasename = doc.CreateElement("basename");
                xebasename.InnerText = de.ExceptionInfo.s_basefullname;
                xe.AppendChild(xebasename);

                XmlElement xesource = doc.CreateElement("source");
                xesource.InnerText = de.ExceptionInfo.s_source;
                xe.AppendChild(xesource);

                XmlElement xetrace = doc.CreateElement("trace");
                xetrace.InnerText = de.ExceptionInfo.s_trace;
                xe.AppendChild(xetrace);

                XmlElement xemsg = doc.CreateElement("msg");
                xemsg.InnerText = de.ExceptionInfo.s_msg;
                xe.AppendChild(xemsg);

                root.AppendChild(xe);
                doc.Save(CExceptionContainer_WuQi.s_xmlfilepath);
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
            }
            return(1);
        }
示例#2
0
        /// <summary>
        /// 处理异常方法
        /// </summary>
        /// <param name="e">接收到得异常,此函数一般接收系统异常,对于应用程序异常可以提前设置catch捕获</param>
        /// <returns>用户提示信息,友好一点啊</returns>
        public static string ProcessException(System.Exception e)
        {
            lock (CExceptionContainer_WuQi.obj_lock)
            {
                if (null == e || false == CExceptionContainer_WuQi.b_initguid)
                {
                    return(CExceptionContainer_WuQi.dictionary_msg[1]);
                }

                Type             t        = e.GetType();
                string           sbase    = null;
                System.Exception issystem = null;
                Type             tt       = t;
                //判断是否为系统异常
                while (tt != null)
                {
                    if (tt.Equals((new System.SystemException()).GetType()))
                    {
                        issystem = e;
                    }
                    tt = tt.BaseType;
                }
                if (null == issystem)
                {
                    sbase = "applicationexception";
                }
                else
                {
                    sbase = "systemexception";
                }
                string   sname  = t.FullName;
                string   source = e.Source;
                string   trace  = e.StackTrace;
                string   smsg   = e.Message;
                DateTime dtime  = DateTime.Now;

                if (0 == sbase.CompareTo("systemexception"))
                {
                    CExceptionDecoraterBase_WuQi decorater = new CExceptionDecoraterBase_WuQi(e, CExceptionContainer_WuQi.msg_id++, dtime, sname, sbase, source, trace, smsg);
                    CExceptionContainer_WuQi.l_exception.Add(decorater.ExceptionInfo);
                    int result = CExceptionContainer_WuQi.InsertSystemToXml(decorater);
                    return(CExceptionContainer_WuQi.dictionary_msg[result]);
                }
                if (0 == sbase.CompareTo("applicationexception"))
                {
                    //应用程序异常暂时不考虑
                }

                return(CExceptionContainer_WuQi.dictionary_msg[1]);
            }
        }
        /// <summary>
        /// 处理异常方法
        /// </summary>
        /// <param name="e">接收到得异常,此函数一般接收系统异常,对于应用程序异常可以提前设置catch捕获</param>
        /// <returns>用户提示信息,友好一点啊</returns>
        public static string ProcessException(System.Exception e)
        {
            lock(CExceptionContainer_WuQi.obj_lock)
            {
                if (null == e || false == CExceptionContainer_WuQi.b_initguid)
                    return CExceptionContainer_WuQi.dictionary_msg[1];

                Type t = e.GetType();
                string sbase = null;
                System.Exception issystem = null;
                Type tt = t;
                //判断是否为系统异常
                while (tt != null)
                {
                    if (tt.Equals((new System.SystemException()).GetType()))
                    {
                        issystem = e;
                    }
                    tt = tt.BaseType;
                }
                if (null == issystem)
                {
                    sbase = "applicationexception";
                }
                else
                {
                    sbase = "systemexception";
                }
                string sname = t.FullName;
                string source = e.Source;
                string trace = e.StackTrace;
                string smsg = e.Message;
                DateTime dtime = DateTime.Now;

                if(0 == sbase.CompareTo("systemexception"))
                {
                    CExceptionDecoraterBase_WuQi decorater = new CExceptionDecoraterBase_WuQi(e, CExceptionContainer_WuQi.msg_id++, dtime, sname, sbase, source, trace, smsg);
                    CExceptionContainer_WuQi.l_exception.Add(decorater.ExceptionInfo);
                    int result = CExceptionContainer_WuQi.InsertSystemToXml(decorater);
                    return CExceptionContainer_WuQi.dictionary_msg[result];

                }
                if(0 == sbase.CompareTo("applicationexception"))
                {
                    //应用程序异常暂时不考虑
                }

                return CExceptionContainer_WuQi.dictionary_msg[1];

            }
        }
        /// <summary>
        /// 将系统异常信息记录到xml文件中
        /// </summary>
        /// <param name="de"></param>
        /// <returns></returns>
        private static int InsertSystemToXml(CExceptionDecoraterBase_WuQi de)
        {
            XmlDocument doc = new XmlDocument();
            XmlElement xe = null;
            try
            {
                doc.Load(CExceptionContainer_WuQi.s_xmlfilepath);
                XmlNode root = doc.SelectSingleNode("exceptions");
                if (null == root)
                    return 0;
                xe = doc.CreateElement("exception");
                xe.SetAttribute("type", "systemexception");

                XmlElement xetime = doc.CreateElement("time");
                xetime.InnerText = de.ExceptionInfo.d_time.ToString().Trim();
                xe.AppendChild(xetime);

                XmlElement xefullname = doc.CreateElement("fullname");
                xefullname.InnerText = de.ExceptionInfo.s_fullname;
                xe.AppendChild(xefullname);

                XmlElement xebasename = doc.CreateElement("basename");
                xebasename.InnerText = de.ExceptionInfo.s_basefullname;
                xe.AppendChild(xebasename);

                XmlElement xesource = doc.CreateElement("source");
                xesource.InnerText = de.ExceptionInfo.s_source;
                xe.AppendChild(xesource);

                XmlElement xetrace = doc.CreateElement("trace");
                xetrace.InnerText = de.ExceptionInfo.s_trace;
                xe.AppendChild(xetrace);

                XmlElement xemsg = doc.CreateElement("msg");
                xemsg.InnerText = de.ExceptionInfo.s_msg;
                xe.AppendChild(xemsg);

                root.AppendChild(xe);
                doc.Save(CExceptionContainer_WuQi.s_xmlfilepath);

            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {

            }
            return 1;
        }