Example #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, Log4NetDbContext log4NetDbContext, ILoggerFactory loggerFactory)
        {
            string log4NetConnectionString = Configuration.GetConnectionString("Log4NetConnection");
            string tableName = Configuration["Logging:TableName"];

            if (env.IsDevelopment())
            {
                string logFilePath = Configuration["Logging:LogFilePath"];
                loggerFactory.AddLog4Net(new[]
                {
                    Log4Net.Appenders.Configuration.CreateConsoleAppender(),
                    Log4Net.Appenders.Configuration.CreateRollingFileAppender(logFilePath),
                    Log4Net.Appenders.Configuration.CreateTraceAppender(),
                    Log4Net.Appenders.Configuration.CreateAdoNetAppender(log4NetConnectionString, tableName)
                });
            }
            else
            {
                loggerFactory.AddLog4Net(new[]
                {
                    Log4Net.Appenders.Configuration.CreateAdoNetAppender(log4NetConnectionString, tableName)
                });
            }

            Log4NetDbInitializer.Initialize(log4NetDbContext);

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            app.UseAuthentication();

            // Enable middleware to serve generated Swagger as a JSON endpoint.
            app.UseSwagger();

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Can The Spam API V1");
            });

            app.UseSession();
            app.UseMvc(routes =>
            {
                routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
 public static void Initialize(Log4NetDbContext context)
 {
     //context.Database.EnsureCreated();
 }