コード例 #1
0
        static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
            Log.WriteException("Unhandled exception", e.ExceptionObject as Exception);

            string path = AppPaths.GenerateCrashDumpPath();

            using (var s = new FileStream(path, FileMode.Create)) {
                using (var sw = new StreamWriter(s)) {
                    sw.WriteLine("OnTopReplica Dump file");
                    sw.WriteLine("This file has been created because OnTopReplica crashed.");
                    sw.WriteLine("Please send it to [email protected] to help fix the bug that caused the crash.");
                    sw.WriteLine();

                    sw.WriteLine("Last exception:");
                    sw.WriteLine(e.ExceptionObject.ToString());
                    sw.WriteLine();

                    sw.WriteLine("Last log entries:");
                    foreach (var logEntry in Log.Queue)
                    {
                        sw.WriteLine(logEntry);
                    }
                    sw.WriteLine();

                    sw.WriteLine("OnTopReplica v.{0}", Application.ProductVersion);
                    sw.WriteLine("OS: {0}", Environment.OSVersion.ToString());
                    sw.WriteLine(".NET: {0}", Environment.Version.ToString());
                    sw.WriteLine("DWM: {0}", WindowsFormsAero.OsSupport.IsCompositionEnabled);
                    sw.WriteLine("Launch command: {0}", Environment.CommandLine);
                    sw.WriteLine("UTC time: {0} {1}", DateTime.UtcNow.ToShortDateString(), DateTime.UtcNow.ToShortTimeString());
                }
            }
        }