Beispiel #1
0
        public static async Task Main(string[] args)
        {
            string env = null;

            if (FirstArgumentIsEnvironment(args))
            {
                env  = args[0];
                args = args.Skip(1).ToArray();
            }

            config = ConfigurationUtilities.LoadAppSettingsJsonConfiguration(env);
            ConfigureDependencyInjection();
            logger = serviceProvider.GetRequiredService <ILogger <Program> >();

            using (logger.BeginScope(
                       "Executing command {command} in {environment} environment",
                       args.FirstOrDefault() ?? "help",
                       env ?? "N/A"))
            {
                Stopwatch timer = Stopwatch.StartNew();

                try
                {
                    // TODO (vladcananau): watch this for attribute inheritance support
                    // https://github.com/adamabdelhamed/PowerArgs/issues/142
                    // await RunWithPowerArgs(args);
                    RunWithCommandLineParser(args);
                    logger.LogInformation("Command successful after: {duration}ms", timer.ElapsedMilliseconds);
                }
                catch (Exception ex)
                {
                    logger.LogError(ex, "Command failed after: {duration}ms", timer.ElapsedMilliseconds);
                }
                finally
                {
                    Console.ReadLine();
                }
            }
        }