// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //-------------------------------------------------------serilog 配置 MVCLogOptions mvcLogOptions = new MVCLogOptions() { LogPath = "D:\\LogFiles_CRM_API",//Configuration[nameof(AuthLogOptions.LogPath)], PathFormat = "{Date}.log" }; var serilog = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.RollingFile(Path.Combine(mvcLogOptions.LogPath, mvcLogOptions.PathFormat), outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}"); MVCLogOptions.EnsurePreConditions(mvcLogOptions); loggerFactory.AddSerilog(serilog.CreateLogger()); // Ensure any buffered events are sent at shutdown 日志的生命周期 IApplicationLifetime appLifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime)); if (appLifetime != null) { appLifetime.ApplicationStopped.Register(Serilog.Log.CloseAndFlush); } app.UseAuthLog(mvcLogOptions);//这个中间件用作记录请求中的过程日志 //---------------------------------------------------serilog 配置 SeedData.Initialize(app.ApplicationServices); //EF初始化数据 if (env.IsDevelopment()) { //开发环境异常处理 app.UseDeveloperExceptionPage(); } else { //生产环境异常处理 app.UseExceptionHandler("/Shared/Error"); } //使用静态文件 app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory()) }); ////Session //app.UseSession(new SessionOptions() { IdleTimeout = TimeSpan.FromMinutes(30) }); //Jwt认证 //ConfigureJwtAuth(app); SeedData.Initialize(app.ApplicationServices); //EF初始化数据 app.UseMvcWithDefaultRoute(); app.UseSwagger() .UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "CRM API V1"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApiVersionDescriptionProvider provider) { app.UseHealthCheck("/HealthCheck", null, new TimeSpan(0, 0, 10)); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //-------------------------------------------------------serilog 配置 MVCLogOptions mvcLogOptions = new MVCLogOptions() { LogPath = "D:\\LogFiles_AuthAdmin_API",//Configuration[nameof(AuthLogOptions.LogPath)], PathFormat = "{Date}.log" }; var serilog = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.RollingFile(Path.Combine(mvcLogOptions.LogPath, mvcLogOptions.PathFormat), outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}"); MVCLogOptions.EnsurePreConditions(mvcLogOptions); loggerFactory.AddSerilog(serilog.CreateLogger()); // Ensure any buffered events are sent at shutdown 日志的生命周期 IApplicationLifetime appLifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime)); if (appLifetime != null) { appLifetime.ApplicationStopped.Register(Serilog.Log.CloseAndFlush); } app.UseAuthLog(mvcLogOptions);//这个中间件用作记录请求中的过程日志 //---------------------------------------------------serilog 配置 //app.UsePetapoco();//use Petapocomiddleware app.UseDapper(); //----dapper if (env.IsDevelopment()) { //开发环境异常处理 app.UseDeveloperExceptionPage(); } else { //生产环境异常处理 app.UseExceptionHandler("/Shared/Error"); } //使用静态文件 app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory()) }); ////Session //app.UseSession(new SessionOptions() { IdleTimeout = TimeSpan.FromMinutes(30) }); SeedData.Initialize(app.ApplicationServices); //EF初始化数据 app.UseMvcWithDefaultRoute(); app.UseSwagger() .UseSwaggerUI(options => { // build a swagger endpoint for each discovered API version foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant()); } }); //往zookeeper注册服务 AuthAPIRegister.registerAuthAPIHostPort(Configuration.GetSection("UrlConfig").GetValue <string>("ZooKeeperList")); //注册到eureka,springcloud服务发现的注册 //app.UseDiscoveryClient(); }
public static void ConfigureAllUIComponent(this IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IConfigurationRoot Configuration) { app.UseHealthCheck("/HealthCheck", null, new TimeSpan(0, 0, 10)); loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); //-------------------------------------------------------serilog 配置 MVCLogOptions mvcLogOptions = new MVCLogOptions() { LogPath = "D:\\LogFiles_API",//Configuration[nameof(AuthLogOptions.LogPath)], PathFormat = "{Date}.log" }; var serilog = new LoggerConfiguration() .MinimumLevel.Debug() .Enrich.FromLogContext() .WriteTo.RollingFile(Path.Combine(mvcLogOptions.LogPath, mvcLogOptions.PathFormat), outputTemplate: "[{Timestamp:HH:mm:ss} {Level}] {Message}{NewLine}{Exception}"); MVCLogOptions.EnsurePreConditions(mvcLogOptions); loggerFactory.AddSerilog(serilog.CreateLogger()); // Ensure any buffered events are sent at shutdown 日志的生命周期 IApplicationLifetime appLifetime = (IApplicationLifetime)app.ApplicationServices.GetService(typeof(IApplicationLifetime)); if (appLifetime != null) { appLifetime.ApplicationStopped.Register(Serilog.Log.CloseAndFlush); } app.UseAuthLog(mvcLogOptions);//这个中间件用作记录请求中的过程日志 //---------------------------------------------------serilog 配置 //app.UsePetapoco();//use Petapocomiddleware app.UseDapper(); //----dapper if (env.IsDevelopment()) { //开发环境异常处理 app.UseDeveloperExceptionPage(); } else { //生产环境异常处理 app.UseExceptionHandler("/Shared/Error"); } //使用静态文件 app.UseStaticFiles(); app.UseStaticFiles(new StaticFileOptions() { FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory()) }); //Session app.UseSession(new SessionOptions() { IdleTimeout = TimeSpan.FromMinutes(30) }); //使用Mvc,设置默认路由为系统登录 app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Login}/{action=Index}/{id?}"); }); //cookie验证 //app.UseCookieAuthentication(CookieAuthMiddleware.GetOptions()); //app.UseOwin(); //app.UseCors(a => { a.AllowAnyOrigin(); }); // Listen for login and logout requests //cookie验证 //app.Map("/loginverify", builder => //{ // builder.Run(async context => // { // var name = context.Request.Form["name"]; // var pwd = context.Request.Form["pwd"]; // if (name == "wushuang" && pwd == "wushuang") // { // var claims = new List<Claim>() { new Claim("name", name), new Claim("role", "admin") }; // var identity = new ClaimsIdentity(claims, "password"); // var principal = new ClaimsPrincipal(identity); // await context.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal); // context.Response.Redirect("/Index/Home"); // } // else // { // await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); // context.Response.Redirect("/Index/Home"); // } // }); //}); //app.Map("/logout", builder => //{ // builder.Run(async context => // { // // Sign the user out / clear the auth cookie // await context.Authentication.SignOutAsync(CookieAuthenticationDefaults.AuthenticationScheme); // // Perform a simple redirect after logout // context.Response.Redirect("/"); // }); //}); }