Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement