Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
                AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

                log = new FileLog(AppDomain.CurrentDomain.BaseDirectory + "logs\\" + AppDomain.CurrentDomain.FriendlyName);
                log.AppendLine("Iniciando");
                if (args.Length == 0)
                {
                    // iniciar la aplicacion
                    Application.Run(new Form1());
                }
                else if (args != null && args.Length > 0 && args[0] == "-service")
                {
                    log.AppendLine("Modo servicio.");
                    System.ServiceProcess.ServiceBase[] ServicesToRun;
                    ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Service() };
                    System.ServiceProcess.ServiceBase.Run(ServicesToRun);
                }
            }
            catch (Exception e)
            {
                log.AppendLine("Error ocurrido {0} {1}", e.TargetSite, e.Message);
            }
            finally
            {
                try
                {
                    if (log != null)
                    {
                        log.AppendLine("Finalizado");
                    }
                }
                catch { }
            }
        }
Beispiel #2
0
 static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     log.AppendLine(e.Exception);
 }
Beispiel #3
0
 public static void LogAppendLine(string text, params object[] args)
 {
     log.AppendLine(text, args);
 }