Startup.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using CZFW.Core;
  2. using CZFW.Framework.Logic;
  3. using CZFW.Framework.Model;
  4. using CZKJ.GBRS2.WebMVC.AppCode;
  5. using log4net;
  6. using log4net.Config;
  7. using log4net.Repository;
  8. using Microsoft.AspNetCore.Builder;
  9. using Microsoft.AspNetCore.Hosting;
  10. using Microsoft.Extensions.Configuration;
  11. using Microsoft.Extensions.DependencyInjection;
  12. using Microsoft.Extensions.Logging;
  13. using System.IO;
  14. using System.Text.Encodings.Web;
  15. using System.Text.Unicode;
  16. namespace CZKJ.GBRS2.WebMVC
  17. {
  18. public class Startup
  19. {
  20. public static ILoggerRepository repository { get; set; }
  21. public Startup(IConfiguration configuration)
  22. {
  23. Configuration = configuration;
  24. ConfigHelper.Configs = Configuration;
  25. repository = LogManager.CreateRepository("NetCoreRepository");
  26. XmlConfigurator.Configure(repository, new FileInfo("log4net.config"));
  27. InitRepository.loggerRepository = repository;
  28. }
  29. public IConfiguration Configuration { get; }
  30. // This method gets called by the runtime. Use this method to add services to the container.
  31. public void ConfigureServices(IServiceCollection services)
  32. {
  33. services.AddMvc(o => o.Filters.Add(typeof(GlobalExceptions)));
  34. services.AddDbContext<CZDbContext>();
  35. services.AddSession();
  36. services.ConfigServies();
  37. services.AddLogging();
  38. services.AddMemoryCache();
  39. services.AddLogging();
  40. services.ConfigureFrameworkServices();
  41. services.AddSingleton(HtmlEncoder.Create(UnicodeRanges.All));
  42. CZHttpContext.ServiceProvider = services.BuildServiceProvider();
  43. }
  44. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
  45. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory logger)
  46. {
  47. logger.AddLog4Net();
  48. app.UseSession();
  49. if (env.IsDevelopment())
  50. {
  51. app.UseBrowserLink();
  52. app.UseDeveloperExceptionPage();
  53. }
  54. else
  55. {
  56. app.UseExceptionHandler("/Home/Error");
  57. }
  58. //logger.AddFile(Configuration.GetSection("FileLogging"));
  59. //logger.AddEventSourceLogger();
  60. app.UseStaticFiles();
  61. app.UseMvc(routes =>
  62. {
  63. routes.MapRoute(
  64. name: "areas",
  65. template: "{area:exists}/{controller=Home}/{action=Index}/{id?}"
  66. );
  67. routes.MapRoute(
  68. name: "default",
  69. template: "{controller=Home}/{action=Index}/{id?}");
  70. });
  71. }
  72. }
  73. }