// The Logger Class public static class Logger { public static void Log(string message) { File.AppendAllText("C:\\MyLogFile.txt", DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() + ":\t" + message + Environment.NewLine); } } // Usage static void Main(string[] args) { Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException); //it must be before Application.Run ... Application.Run(); } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { Logger.Log(e.Exception.ToString()); }