diff --git a/24Hour/Program.cs b/24Hour/Program.cs index 17c60fc..9b331c2 100644 --- a/24Hour/Program.cs +++ b/24Hour/Program.cs @@ -21,9 +21,11 @@ using System.Reflection; using Elight.Entity; using _24Hour; using Microsoft.Extensions.DependencyInjection; +using _24Hour.Filter; #region builder +Console.Title = "24HourServer"; var builder = WebApplication.CreateBuilder(args); var Configuration = builder.Configuration; @@ -39,7 +41,10 @@ AutoMapper.IConfigurationProvider config = new MapperConfiguration(cfg => builder.Services.AddSingleton(config); builder.Services.AddScoped(); #endregion -builder.Services.AddControllers().AddJsonOptions(options => +builder.Services.AddControllers(ops => +{ + ops.Filters.Add(); +}).AddJsonOptions(options => { options.JsonSerializerOptions.PropertyNamingPolicy = null; options.JsonSerializerOptions.Converters.Add(new Elight.Utility.DateTimeNullableConverter()); @@ -49,10 +54,17 @@ builder.Services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); - options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); + options.JsonSerializerOptions.Converters.Add(new Elight.Utility.NullableConverter()); + + }); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle builder.Services.AddEndpointsApiExplorer(); + + +builder.Host.ConfigureLogging(opt => +{ +}); #region Swagger文件 builder.Services.AddSwaggerGen(c => { @@ -173,12 +185,11 @@ builder.Services.AddAuthentication(options => }).AddScheme(nameof(ResponseAuthenticationHandler), o => { }); - builder.Services.AddHttpClient(opt => { opt.BaseAddress = new Uri("https://api.weixin.qq.com/sns"); }); -builder.Services.AddHttpClient(opt => +builder.Services.AddHttpClient(opt => { opt.BaseAddress = new Uri(Configuration.GetSection("CaseTwenty:SysAddress").Value); }); @@ -213,6 +224,9 @@ builder.Services.TryAddSingleton(); builder.Services.TryAddSingleton(); builder.Services.AddHostedService(); // 注册Quartz.NET的托管服务 + +builder.Logging.AddLog4Net("log4net.config"); + //Task.Factory.StartNew(() => //{ // try @@ -256,6 +270,7 @@ app.UseStaticFiles(); //使用httpclient日志记录 必须在UseStaticFiles下面 app.UseHttpLogging(); + app.UseRouting(); app.UseAuthentication(); // 启用身份验证中间件 app.UseAuthorization(); // 启用授权中间件