示例#1
0
        public static void HandleException(Exception e)
        {
            Console.WriteLine();

            if (Util.IsLinux)
            {
                logger.Error(e, "Unhandled exception");
            }
            else
            {
                var dump = Path.Combine(Path.GetTempPath(), string.Format("DotOPDS_{0}.mdmp", Guid.NewGuid()));
                using (var fs = new FileStream(dump, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
                {
#if DEBUG
                    var flags = MiniDump.Option.WithFullMemory
                                | MiniDump.Option.WithFullMemoryInfo
                                | MiniDump.Option.WithThreadInfo;
#else
                    var flags = MiniDump.Option.WithThreadInfo
                                | MiniDump.Option.WithProcessThreadData
                                | MiniDump.Option.WithHandleData;
#endif
                    MiniDump.Write(fs.SafeFileHandle, flags);
                }
                logger.Error("Something bad happened... Dump written to {0}", dump);
            }

            Environment.Exit(1);
        }
示例#2
0
 public static void SaveMiniDump(Exception exception)
 {
     if (makeMiniDump)
     {
         using (FileStream fs = new FileStream($"./logs/log-{Birthdate}.mdmp", FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
         {
             MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.WithFullMemory, MiniDump.ExceptionInfo.Present);
         }
     }
     else
     {
         if (exception.InnerException != null)
         {
             Log.Fatal("TERMINATED BY UNHANDLED EXCEPTION: {@Exception}, {@InnerException}, {@GroundZero}",
                       exception,
                       exception.InnerException,
                       exception.InnerException.StackTrace);
         }
         else
         {
             Log.Fatal("TERMINATED BY UNHANDLED EXCEPTION: {@Exception}, {@GroundZero}",
                       exception,
                       exception.StackTrace);
         }
     }
 }
示例#3
0
    static public void write_dump(string desc)
    {
        string fname = "MiniDmp_" + DateTime.Now.ToString("yyyy-MM-dd_hh_mm_ss") + ".dmp";

        MessageBox.Show("发生未知错误,崩溃了,请将此窗口截图发送;如有必要,也请发送" + fname + " 以便修错误\r\n " + desc);

        var dic = new Dictionary <string, string>();

        dic["msg"] = desc;
        var c = new System.Net.Http.FormUrlEncodedContent(dic);

        try
        {
            var p = new System.Net.Http.HttpClient();
            var r = p.PostAsync(tools.helper.count_server_addr + "/sssgbsssgb/logerror", c).Result;
        }
        catch (Exception)
        {
        }

        using (FileStream fs = new FileStream(fname, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
        {
            MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.Normal);
        }
    }
示例#4
0
        internal static void RunFatalAction(Exception ex)
        {
            string message = "Ocorreu um erro inesperado e o aplicativo teve que ser encerrado.";

#if DEBUG
            message += "\n\nMensagem de erro:\n" + ex?.Message;
#endif


            ShowNewThreadMessageBox(message, MessageBoxIcon.Stop);

            Application.ExitThread();

            var dir      = GetAppDataDir("dumps");
            var fileName = DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss") + ".dmp";
            var path     = Path.Combine(dir.FullName, fileName);

            MiniDump.Write(path, MiniDump.Option.Normal, true);

            try
            {
                Context.Shutdown();
            }
            catch (Exception)
            { }
        }
示例#5
0
        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            if (!Debugger.IsAttached || true)
            {
                var exception = e.ExceptionObject as Exception;

                LogTo.FatalException("Unhandled exception", exception);

                var result = MessageBox.Show($"{exception.GetType().FullName}: {exception.Message}\n" +
                                             "This error will be automatically reported. Create minidump? You can use it to manually report the issue to me.", "Unhandled exception",
                                             MessageBoxButton.YesNoCancel, MessageBoxImage.Error);

                Report();

                if (result == MessageBoxResult.Yes)
                {
                    string date   = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
                    string path   = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "dumps", $"dump_{date}.mdmp");
                    string folder = Path.GetDirectoryName(path);

                    if (!Directory.Exists(folder))
                    {
                        Directory.CreateDirectory(folder);
                    }

                    using (var fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
                    {
                        MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.Normal | MiniDump.Option.WithIndirectlyReferencedMemory | MiniDump.Option.WithDataSegs, MiniDump.ExceptionInfo.Present);
                    }

                    using (var file = File.OpenWrite(path + ".zip"))
                        using (var zip = new ZipArchive(file, ZipArchiveMode.Create))
                        {
                            using (var dumpFile = File.OpenRead(path))
                                using (var entry = zip.CreateEntry(Path.GetFileName(path)).Open())
                                {
                                    dumpFile.CopyTo(entry);
                                }

                            using (var logFile = File.Open("logs/lrm.log", FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                                using (var entry = zip.CreateEntry("log.txt").Open())
                                {
                                    logFile.CopyTo(entry);
                                }
                        }

                    File.Delete(path);

                    Process.Start("explorer.exe", $"/select, \"{path}.zip\"");
                }

                if (e.IsTerminating)
                {
                    Legendary_Rune_Maker.MainWindow.DisposeTaskbar();
                    Process.GetCurrentProcess().Kill();
                }
            }
示例#6
0
 /// <summary>
 /// 提交按钮
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void Button1_Click(object sender, EventArgs e)
 {
     try
     {
         SetButtonDisabled(button1, false);
         //程序崩溃生成转储文件
         if (args == null || args.Length == 0)
         {
             MessageBox.Show(this, $"args=null不允许操作!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
         var mainPath = args[0];
         if (!File.Exists(mainPath))
         {
             MessageBox.Show(this, $"{mainPath} 文件不存在!", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             return;
         }
         var programeName = Path.GetFileNameWithoutExtension(mainPath);
         var path         = Application.StartupPath + $"\\CrashDumps\\";
         if (!Directory.Exists(path))
         {
             Directory.CreateDirectory(path);
         }
         path += $"{DateTime.Now.ToString("yyyy-MM-dd HH.mm.ss")}{programeName}.dmp";
         using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
         {
             MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.WithFullMemory, programeName);
         }
         Logger.WriteProfilerLog(new Tuple <string, string>("CrashLog", _eventId), $"创建Crash文件成功!{path}");
         //发送报告,并上传dmp文件到服务器
         if (checkBox1.Checked)
         {
             Logger.WriteProfilerLog(new Tuple <string, string>("CrashLog", _eventId), $"上传Crash文件到服务器...");
         }
         //重启宿主
         if (checkBox2.Checked)
         {
             Logger.WriteProfilerLog(new Tuple <string, string>("CrashLog", _eventId), $"杀进程:{programeName},重启宿主:{mainPath}");
             //杀掉进程
             var     rtKill = SystemUtility.KillProcess(programeName);
             Process pr     = new Process();
             pr.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
             pr.StartInfo.FileName         = mainPath;//重启宿主
             pr.Start();
             Environment.Exit(0);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(this, $"提交异常:{ex.Message}", "警告", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     finally
     {
         SetButtonDisabled(button1, true);
     }
 }
示例#7
0
        private static void HandleException(Exception exception)
        {
            if (exception == null)
            {
                return;
            }
            var zipFile = Path.Combine(ApplicationPath.AppData,
                                       $"{Application.ProductName}-crashlog-{DateTime.UtcNow.Date.Day}_{DateTime.UtcNow.Date.Month}_{DateTime.UtcNow.Date.Year}.zip");
            var exceptionMessage = exception.Message;

            if (exception.InnerException != null)
            {
                exceptionMessage += $"\n{exception.InnerException.Message}";
            }

            var message =
                $@"It seems {Application.ProductName} has crashed.

{exceptionMessage}

Do you want to save a log of the error that occurred?
This could be useful to fix bugs. Please post this file in the issues section
File Location: {zipFile}";
            var result = MessageBox.Show(message, $@"{Application.ProductName} crashed...", MessageBoxButtons.YesNo,
                                         MessageBoxIcon.Error);

            if (result == DialogResult.Yes)
            {
                using (new HourGlass())
                {
                    var fileName = Path.Combine(ApplicationPath.Default, Environment.MachineName + ".dmp");
                    using (
                        var fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite,
                                                FileShare.Write))
                    {
                        MiniDump.Write(fs.SafeFileHandle,
                                       MiniDump.Option.Normal | MiniDump.Option.WithThreadInfo | MiniDump.Option.WithHandleData |
                                       MiniDump.Option.WithDataSegs, MiniDump.ExceptionInfo.Present);
                    }

                    Log.Fatal(exception, "Exception Occurred ");

                    if (File.Exists(zipFile))
                    {
                        File.Delete(zipFile);
                    }

                    Log.CloseAndFlush();

                    ZipFile.CreateFromDirectory(ApplicationPath.Default, zipFile);
                }

                Process.Start("explorer.exe", "/select," + @zipFile);
            }
        }
示例#8
0
        private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            var fileName = string.Format(@"turbofilmvpn_crash_{0}_{1}.mdmp", DateTime.Today.ToShortDateString(), DateTime.Now.Ticks);

            if (e.ExceptionObject != null)
            {
                string stackTrace = ((Exception)e.ExceptionObject).StackTrace;
            }
            using (var stream = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
            {
                MiniDump.Write(stream.SafeFileHandle, MiniDump.Option.WithFullMemory, e.ExceptionObject != null ? MiniDump.ExceptionInfo.Present : MiniDump.ExceptionInfo.None);
            }
        }
示例#9
0
        static void EngineFailed(string allText, string title)
        {
#if !DEBUG
            MiniDump.Write();
#endif
            MessageBox.Show(
                allText,
                title,
                MessageBoxButtons.OK,
                MessageBoxIcon.Error
                );
            Critical.NoThrow(() =>
            {
                GameAPI.I.Core.Log.Error("--- " + title);
                GameAPI.I.Core.Log.Error(allText);
                GameAPI.I.Core.Log.End();
            });
        }
示例#10
0
        private static string DumpProcess(bool isFirstChance = false)
        {
            var time = DateTime.Now;

            string fileName;

            if (isFirstChance)
            {
                fileName = Path.Combine(DumpDirectory, "tank_inspector_previous_first_chance.dmp");
            }
            else
            {
                fileName = Path.Combine(DumpDirectory, $"tank_inspector_{time.ToString("yyyy_MM_dd_HH_mm_ss")}.dmp");
            }

            using (FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.ReadWrite, FileShare.Write))
            {
                MiniDump.Write(fs.SafeFileHandle, MiniDump.Option.Normal);
            }
            _hasDumped = true;
            return(fileName);
        }
示例#11
0
        private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            string dumpFile = System.IO.Path.Combine(System.Environment.CurrentDirectory, string.Format("thread-dump-{0}.dmp", DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss")));

            MiniDump.Write(dumpFile);
        }