You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.8 KiB

  1. namespace TruckAP
  2. {
  3. using log4net;
  4. using log4net.Config;
  5. using System;
  6. using System.IO;
  7. using System.Reflection;
  8. using System.Windows.Forms;
  9. static class Program
  10. {
  11. private static ILog _log = LogManager.GetLogger(typeof(Program));
  12. /// <summary>
  13. /// The main entry point for the application.
  14. /// </summary>
  15. [STAThread]
  16. static void Main()
  17. {
  18. LoadLog4netConfig();
  19. _log.Info("AP Start");
  20. string sSuffix = "";
  21. string[] saCmd = Environment.GetCommandLineArgs();
  22. foreach (string sCmd in saCmd)
  23. {
  24. if (sCmd == "-a" || sCmd == "-v")
  25. {
  26. sSuffix = sCmd;
  27. break;
  28. }
  29. }
  30. System.Threading.Mutex mu = new System.Threading.Mutex(true, string.Format("Global\\{0}{1}", typeof(Program).GUID, sSuffix), out bool IsAppRunning);
  31. if (!IsAppRunning)
  32. {
  33. _log.Error("Leave Program without doing anything(Mutex)");
  34. mu.Dispose();
  35. Environment.Exit(1);
  36. }
  37. _log.Info("Launch UI");
  38. Application.SetHighDpiMode(HighDpiMode.SystemAware);
  39. Application.EnableVisualStyles();
  40. Application.SetCompatibleTextRenderingDefault(false);
  41. Application.Run(new Form1());
  42. }
  43. private static void LoadLog4netConfig()
  44. {
  45. var repository = LogManager.CreateRepository(
  46. Assembly.GetEntryAssembly(),
  47. typeof(log4net.Repository.Hierarchy.Hierarchy)
  48. );
  49. XmlConfigurator.Configure(repository, new FileInfo("Log4Net.config"));
  50. }
  51. }
  52. }