Пример #1
0
        public static void ReportError(IWin32Window parentForm, Type sourceType, string userMessage, Exception ext)
        {
            ErrorReportInfo info = CreateInfo(sourceType, userMessage, ext);
            string          dm   = "Error:" + userMessage;

            if (ext != null)
            {
                dm = dm + " " + ext.Message;
            }
            System.Diagnostics.Debug.WriteLine(dm);
            if (System.Environment.UserInteractive)
            {
                using (dlgError dlg = new dlgError())
                {
                    dlg.ReportInfo = info;
                    dlg.ShowDialog(parentForm);
                }
            }
        }
Пример #2
0
        public static ErrorReportInfo CreateInfo(
            Type sourceType,
            string userMessage,
            Exception ext)
        {
            ErrorReportInfo info = new ErrorReportInfo();

            info.UserMessage = userMessage;
            try
            {
                info.ApplicationName = System.Windows.Forms.Application.ProductName;
            }
            catch (Exception ext2)
            {
                info.ApplicationName = ext2.Message;
            }
            try
            {
                info.AppVersion = System.Windows.Forms.Application.ProductVersion;
            }
            catch (Exception e2)
            {
                info.AppVersion = e2.Message;
            }
            try
            {
                info.CommandLine = System.Environment.CommandLine;
            }
            catch (Exception e2)
            {
                info.CommandLine = e2.Message;
            }
            try
            {
                info.AppPath = System.Windows.Forms.Application.ExecutablePath;
            }
            catch (Exception e)
            {
                info.AppPath = e.Message;
            }
            try
            {
                info.OSVersion = System.Environment.OSVersion.ToString();
            }
            catch (Exception e)
            {
                info.OSVersion = e.Message;
            }
            try
            {
                info.RuntimeVersion = System.Environment.Version.ToString();
            }
            catch (Exception e)
            {
                info.RuntimeVersion = e.Message;
            }
            if (ext != null)
            {
                info.ExceptionString = ext.ToString();
                info.SystemMessage   = ext.Message;
            }
            if (sourceType != null)
            {
                info.SourceType = sourceType.FullName;
                AssemblyName asmName = new System.Reflection.AssemblyName(sourceType.Assembly.FullName);
                info.SourceModuleName     = asmName.Name;
                info.SourceModuleVersion  = asmName.Version.ToString();
                info.SourceModuleCodeBase = sourceType.Assembly.CodeBase;
            }
            return(info);
        }