Inheritance: System.NotifyPropertyChangedBase
示例#1
0
        public static bool ExceptionOut(Exception ex)
        {
            lock (LockObj)
            {
                var IsTerminatePermission = true;

                var ident = WindowsIdentity.GetCurrent();
                var princ = new WindowsPrincipal(ident);

                var errorReport = string.Join(Environment.NewLine,
                                              string.Format(Properties.Resources.UnhandledExceptionText1, DateTime.Now),

                                              // 権限書き出し
                                              string.Format(Properties.Resources.UnhandledExceptionText11 + princ.IsInRole(WindowsBuiltInRole.Administrator)),
                                              string.Format(Properties.Resources.UnhandledExceptionText12 + princ.IsInRole(WindowsBuiltInRole.User)),
                                              "",

                                              // OSVersion,AppVersion書き出し
                                              string.Format(Properties.Resources.UnhandledExceptionText4),
                                              string.Format(Properties.Resources.UnhandledExceptionText5, Environment.OSVersion.VersionString),
                                              string.Format(Properties.Resources.UnhandledExceptionText6, Environment.Version),
                                              string.Format(Properties.Resources.UnhandledExceptionText7, MyCommon.GetAssemblyName(), FileVersion),

                                              ExceptionOutMessage(ex, ref IsTerminatePermission));

                var logPath = MyCommon.GetErrorLogPath();
                if (!Directory.Exists(logPath))
                {
                    Directory.CreateDirectory(logPath);
                }

                var now      = DateTime.Now;
                var fileName = string.Format("{0}-{1:0000}{2:00}{3:00}-{4:00}{5:00}{6:00}.log", GetAssemblyName(), now.Year, now.Month, now.Day, now.Hour, now.Minute, now.Second);
                using (var writer = new StreamWriter(Path.Combine(logPath, fileName)))
                {
                    writer.Write(errorReport);
                }

                var settings = SettingManager.Common;
                var mainForm = Application.OpenForms.OfType <TweenMain>().FirstOrDefault();

                ErrorReport report;
                if (mainForm != null && !mainForm.IsDisposed)
                {
                    report = new ErrorReport(mainForm.TwitterInstance, errorReport);
                }
                else
                {
                    report = new ErrorReport(errorReport);
                }

                report.AnonymousReport = settings.ErrorReportAnonymous;

                OpenErrorReportDialog(mainForm, report);

                // ダイアログ内で設定が変更されていれば保存する
                if (settings.ErrorReportAnonymous != report.AnonymousReport)
                {
                    settings.ErrorReportAnonymous = report.AnonymousReport;
                    settings.Save();
                }

                return(false);
            }
        }