Ejemplo n.º 1
0
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory, SwaggerSettings swaggerSettings)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            #region App Register
            app.UseAPIConfig(loggerFactory, swaggerSettings, useCORS: true, useSwagger: true);
            #endregion

            #region End Point & Routes
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
            #endregion

            #region EF Create & Migrate
            SharedKernal.Helper.SystemLogger.ILogger logger = app.ApplicationServices.GetRequiredService <SharedKernal.Helper.SystemLogger.ILogger>();
            AppDbContext context = app.ApplicationServices.GetRequiredService <AppDbContext>();
            logger.WriteLog(CommonEnum.LogLevelEnum.Information, MethodBase.GetCurrentMethod(), message: "Ensure database created.");
            try
            {
                logger.WriteLog(CommonEnum.LogLevelEnum.Information, MethodBase.GetCurrentMethod(), message: "Database already up to date.");
                context.Database.Migrate();
                logger.WriteLog(CommonEnum.LogLevelEnum.Information, MethodBase.GetCurrentMethod(), message: "Migration has been applied.");
            }
            catch (System.Exception exception)
            {
                logger.WriteLog(CommonEnum.LogLevelEnum.Error, MethodBase.GetCurrentMethod(), exception: exception);
            }
            #endregion
        }
Ejemplo n.º 2
0
        public static void Main(string[] args)
        {
            IHost host = CreateHostBuilder(args).Build();

            using IServiceScope scope = host.Services.CreateScope();
            AutoFacHelper.Container   = scope.ServiceProvider;
            SharedKernal.Helper.SystemLogger.ILogger logger = scope.ServiceProvider.GetRequiredService <SharedKernal.Helper.SystemLogger.ILogger>();
            logger.WriteLog(SharedKernal.Enum.CommonEnum.LogLevelEnum.Information, System.Reflection.MethodBase.GetCurrentMethod(), message: $"Service Started ...");
            host.Run();
        }