private static void OnCurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e) { if (!e.IsTerminating) { return; } MessageBox.Show(string.Format("发生严重错误,即将退出。。。详情请查看error.log。{0}{1}", Environment.NewLine, (e.ExceptionObject as Exception)?.Message), "Osu Player", MessageBoxButton.OK, MessageBoxImage.Error); ConcurrentFile.AppendAllText("error.log", string.Format(@"===================={0}===================={1}{2}{3}{4}", DateTime.Now, Environment.NewLine, e.ExceptionObject, Environment.NewLine, Environment.NewLine)); Environment.Exit(1); }
private static void WriteToLog(string contents) { contents = string.Format("-----{0} {1}{2}{3}{4}", DateTime.Now.ToLongDateString(), DateTime.Now.ToLongTimeString(), Environment.NewLine, contents, Environment.NewLine + Environment.NewLine); string logPath = Path.Combine(Domain.CurrentDirectory, "log"); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } ConcurrentFile.AppendAllText(Path.Combine(logPath, "exception.log"), contents); }