public MainForm() { InitializeComponent(); _logManager = CustomLogManager.GetInstance(); ((CustomLogManager)_logManager).LogChangedEvent += MainForm_LogChangedEvent; StartCollectService(); }
private void StartCollectService() { if (_process != null) { MessageBox.Show("服务已启动"); } else { _process = new ActiveProccess(CustomLogManager.GetInstance()); _process.Run(Address, Port); } }
private static void Main() { CustomLogManager.GetInstance().WriteLogToFile(string.Empty.PadRight(6) + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " : " + "开始运行程序" + "\r\n"); try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //处理未捕获的异常 Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //处理UI线程异常 Application.ThreadException += Application_ThreadException; //处理非UI线程异常 AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; //运行主程序 Application.Run(new MainForm()); } catch (Exception e) { CustomLogManager.GetInstance().WriteLogToFile(string.Empty.PadRight(6) + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " : " + e.Message + "\r\n"); } }
public static CustomLogManager GetInstance() { return(_instance ?? (_instance = new CustomLogManager())); }
private static void Application_ThreadException(object sender, ThreadExceptionEventArgs e) { CustomLogManager.GetInstance().WriteLogToFile(string.Empty.PadRight(6) + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " : " + e.Exception + "\r\n"); }
private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) { CustomLogManager.GetInstance().WriteLogToFile(string.Empty.PadRight(6) + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + " : " + e.ExceptionObject + "\r\n"); }