コード例 #1
0
 static void Main()
 {
     try
     {
         Application.EnableVisualStyles();
         Application.SetCompatibleTextRenderingDefault(false);
         EventLogManager.CreateEventLog();
         EventLogManager.WriteEventLog(@"App Engine " + Process.GetCurrentProcess().ProcessName + @" starting - " + DateTime.Now.ToString(), EventLogEntryType.Information, 1);
         Application.Run(new Form1(Process.GetCurrentProcess().ProcessName));
         EventLogManager.WriteEventLog(@"App Engine " + Process.GetCurrentProcess().ProcessName + @" exiting - " + DateTime.Now.ToString(), EventLogEntryType.Information, 3);
         ReportManager.app.Quit();
     }
     catch (Exception e)
     {
         string message = AppCommon.AppendInnerExceptionMessages("ERROR: Could not start AppEngine - " + e.Message, e);
         if (message.ToUpper().Contains("NOT ALLOWED"))
         {
             message += " - Make sure the AppEngine is running with Administrator privledges.";
         }
         MessageBox.Show(message, "App Engine Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #2
0
        public static void Log(string logMessage, EventLogEntryType type)
        {
            // writes message to the specified listbox and the EventLog as an Information type
            int eventId = 0; // type 0 = error, 2 = information

            if (type == EventLogEntryType.Error)
            {
                eventId = 0;
            }
            if (type == EventLogEntryType.Information)
            {
                eventId = 2;
            }
            try
            {
                string prefix = DateTime.Now.ToString("MM/dd/yy HH:MM:ss tt - ");
                if (type == EventLogEntryType.Error)
                {
                    prefix += "ERROR: ";
                }
                ;
                if (mainformRichTextBox.InvokeRequired)
                {
                    // InvokeRequired is true prior to the instatiation of the UI thread
                    mainformRichTextBox.Invoke((MethodInvoker)(() => mainformRichTextBox.AppendText(prefix + logMessage + Environment.NewLine)));
                }
                else
                {
                    // add message to form
                    mainformRichTextBox.AppendText(prefix + logMessage + Environment.NewLine);
                }
                EventLogManager.WriteEventLog(logMessage, type, eventId);
            }
            catch (Exception e)
            {
                string message = AppendInnerExceptionMessages("Log: Could not log message - " + e.Message, e);
                throw new Exception(message);
            }
        } // Log()