Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .Enrich.FromLogContext()
                         .CreateLogger();

            try
            {
                Log.Information("Inicializando a API!");
                var host = CreateHostBuilder(args).Build();

                await DbMigration.EnsureSeedData(host);

                await host.RunAsync().ConfigureAwait(false);;
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Erro ao inicializar!");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="args"></param>
        /// <returns></returns>
        public static async Task Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         .Enrich.FromLogContext()
                         .CreateLogger();

            var seed    = args.Any(x => x == SeedArgs);
            var envSeed = Environment.GetEnvironmentVariable("SEED")?.ToLower();

            seed = seed || envSeed == "true";

            if (seed)
            {
                args = args.Except(new[] { SeedArgs }).ToArray();
            }

            try
            {
                Log.Information("Inicializando a API!");
                var host = CreateHostBuilder(args)

                           .Build();

                //dotnet run /seed
                if (seed)
                {
                    await DbMigration.EnsureSeedData(host);
                }

                host.Run();
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Erro ao inicializar!");
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }