From 1003c2a10566651740a3b0eeb9dafbe9f9d068c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=BD=87=E9=98=B3=20=E9=82=B9?= Date: Mon, 30 Oct 2023 09:21:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0log4net=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 24Hour/Program.cs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) 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(); // 启用授权中间件