初次提交
This commit is contained in:
48
C-Windows-1/Program.cs
Normal file
48
C-Windows-1/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace C_Windows_1
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// 应用程序的主入口点。
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
|
||||
Application.ThreadException += Application_ThreadException;
|
||||
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
|
||||
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
Application.Run(new Form1());
|
||||
}
|
||||
|
||||
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
|
||||
{
|
||||
// 获取项目的 Debug 目录路径
|
||||
string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "error.txt");
|
||||
using (FileStream efs = new FileStream(logFilePath, FileMode.Append))
|
||||
{
|
||||
byte[] data = System.Text.Encoding.Default.GetBytes("CurrentDomain_UnhandledException::" + e.ToString() + ",object:" + e.ExceptionObject.ToString());
|
||||
efs.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
|
||||
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
|
||||
{
|
||||
// 获取项目的 Debug 目录路径
|
||||
string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "error.txt");
|
||||
using (FileStream efs = new FileStream(logFilePath, FileMode.Append))
|
||||
{
|
||||
byte[] data = System.Text.Encoding.Default.GetBytes("Application_ThreadException:" + e.ToString());
|
||||
efs.Write(data, 0, data.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user