Example #1
0
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            IOptions <ServerOptions> serverOptions,
            SeedDbData seeder)
        {
            // When in development
            if (env.IsDevelopment())
            {
                // Log in Debug Window and in Console using the minimum log level from options
                loggerFactory.AddDebug(serverOptions.Value.LogLevel);
                loggerFactory.AddConsole(serverOptions.Value.LogLevel);

                // Use developer exception pages
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            // When in staging/production
            else
            {
                // Log in files (using the Serilog library) using the minimum log level from options
                AwesomeMethods.CreateSerilogLogger(env, serverOptions.Value.LogLevel);
                loggerFactory.AddSerilog();

                // Use custom exception page
                app.UseExceptionHandler("/Home/Error");
            }

            // Add custom middlware to log exceptions and fall back to the previous exception handlers
            app.UseLogExceptionHandler();

            // Configure the localization. en-US and el-GR cultures are supported with en-US being
            // the default one
            ConfigureLocalization(app);

            // Enable static files so files in wwwroot can be found and served
            app.UseStaticFiles();

            // Apply initial data in the database
            seeder.EnsureSeedInitialDataAsync().Wait();;

            // Enable Identity
            app.UseIdentity();

            // Enable IdentityServer
            app.UseIdentityServer();

            // Enable MVC with a default template
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}");
            });
        }
Example #2
0
        public void Configure(
            IApplicationBuilder app,
            IHostingEnvironment env,
            ILoggerFactory loggerFactory,
            IOptions <ApiOptions> apiOptions,
            SeedDbData seeder)
        {
            // When in development
            if (env.IsDevelopment())
            {
                // Log in Debug Window and in Console using the minimum log level from options
                loggerFactory.AddDebug(apiOptions.Value.LogLevel);
                loggerFactory.AddConsole(apiOptions.Value.LogLevel);
            }
            // When in staging/production
            else
            {
                // Log in files (using the Serilog library) using the minimum log level from options
                AwesomeMethods.CreateSerilogLogger(env, apiOptions.Value.LogLevel);
                loggerFactory.AddSerilog();
            }

            // Custom Middleware for exception handling. This is added first in the pipeline to catch
            // unhandled exceptions from the whole request
            app.UseApiExceptionHandler();

            // Uncomment the line below to raise exception for debugging purposes to test the above handler
            // app.UseExceptionRaiser();

            // Configure the localization. en-US and el-GR cultures are supported with en-US being
            // the default one
            ConfigureLocalization(app);

            // Configure the field mapping between Models and ViewModels
            ConfigureMapping();

            // Enable MVC. No routes specified here. We use attribute routing in controllers
            app.UseMvc();

            // Apply initial data in the database
            seeder.EnsureSeedInitialDataAsync().Wait();
        }