コード例 #1
0
		public static void Main(string[] args)
		{
			// NLog: setup the logger first to catch all errors
			NLog.Logger logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
			try
			{
				bool isService = !Debugger.IsAttached && args.Contains("--service");
				IWebHostBuilder builder = CreateWebHostBuilder(args.Where(arg => arg != "--service").ToArray());

				if (isService)
				{
					string pathToExe = Process.GetCurrentProcess().MainModule.FileName;
					string pathToContentRoot = Path.GetDirectoryName(pathToExe);
					builder.UseContentRoot(pathToContentRoot);
				}

				IWebHost host = builder.Build();

				if (isService)
				{
					host.RunAsPaymentService();
				}
				else
				{
					host.Run();
				}

				logger.Debug("init main");
			}
			catch (Exception ex)
			{
				//NLog: catch setup errors
				logger.Error(ex, "Stopped program because of exception");
				throw;
			}
			finally
			{
				logger.Debug("suht down");
				// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
				NLog.LogManager.Shutdown();
			}
		}