コード例 #1
0
            /// <summary>
            /// Creates an error-log entry and quits the application.
            /// </summary>
            /// <param name="ex">The exception details that will be written to the file.</param>
            /// <param name="details">(Optional) A custom message to further elaborate on what the error is.</param>
            public static void Log(Exception ex, string details = null, EnumErrorSeverity severity = 0)
            {
                FileInfo logFile = GetLogFile();

                using (System.IO.StreamWriter file =
                           new System.IO.StreamWriter(logFile.FullName, true))
                {
                    //No need to close, as "Using" does so automatically.
                    file.WriteLine(Environment.NewLine);
                    file.WriteLine(DateTime.Now + " - " + details + Environment.NewLine + ex);
                }
                new ErrorPrompt(severity);
            }
コード例 #2
0
        /// <summary>
        /// Constructor.
        /// Shows the error message and determines if the game will shut down based on severity.
        /// </summary>
        /// <param name="severity"></param>
        public ErrorPrompt(EnumErrorSeverity severity)
        {
            InitializeComponent();
            Severity = severity;
            //The error message displayed
            string errorMessage = $"A" + (severity == EnumErrorSeverity.Fatal ? " fatal" : "n") +
                                  " error has occured: Detailed information can be found" + Environment.NewLine + "in the Log file named \"Error Log - " + DateTime.Now.Date.ToString("dd/MM/yyyy") + "\"";

            this.DataContext = new { message = errorMessage };
            //Make the window fit itself to the content (the message and the buttons)
            SizeToContent = SizeToContent.WidthAndHeight;
            Window mainWindow = Application.Current.MainWindow;

            this.Left = mainWindow.Left + (mainWindow.Width - this.Width) / 2;
            this.Top  = mainWindow.Top + (mainWindow.Height - this.Height) / 2;
            //Show the window
            ShowDialog();
        }