~grubng-dev/grubng/tools-urlsdb

« back to all changes in this revision

Viewing changes to Main.cs

  • Committer: thindil
  • Date: 2011-04-21 08:52:10 UTC
  • Revision ID: thindil2@gmail.com-20110421085210-iwtl1ntnh5aiiy9a
added catching unhandled exception

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
                public static void Main(string[] args)
42
42
                {
43
43
                        SetProcessName("grub-urlsdb");
 
44
                        AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(MainUnhandledException);
44
45
                        //If no arguments for program, show help
45
46
                        if (args.Length == 0)
46
47
                        {
521
522
                                }
522
523
                        }
523
524
                }
 
525
                
 
526
                /// <summary>
 
527
                /// Main function for catch unhandled exceptions. Write informations about exception to error.log.
 
528
                /// </summary>
 
529
                /// <param name="sender">
 
530
                /// A <see cref="System.Object"/> unused.
 
531
                /// </param>
 
532
                /// <param name="args">
 
533
                /// A <see cref="UnhandledExceptionEventArgs"/> provide informations about error (source, stacktrace,
 
534
                /// general info about error)
 
535
                /// </param>
 
536
                static void MainUnhandledException(object sender, UnhandledExceptionEventArgs args)
 
537
                {
 
538
                        if (sender != null)
 
539
                        {
 
540
                                sender = null;
 
541
                        }
 
542
                        Exception e = (Exception)args.ExceptionObject;
 
543
                        string tdate = DateTime.Now.ToString("yyyy/MM/dd/HH:mm:ss");
 
544
                        FileStream errorlog = File.Open("error.log", FileMode.Append);
 
545
                        StreamWriter logstream = new StreamWriter(errorlog); 
 
546
                        logstream.WriteLine(tdate + " Caught: " + e.GetType().ToString() + " " + e.Message);
 
547
                        logstream.WriteLine("  Source: " + e.Source);
 
548
                        logstream.WriteLine("  StackTrace: " + e.StackTrace);
 
549
                        logstream.WriteLine("  TargetSite: " + e.TargetSite);
 
550
                        logstream.Close();
 
551
                }
524
552
        }
525
553
        
526
554
        /// <summary>