Browse Source

添加log4net日志记录器

develop-lawyerExampaper
胡超1 2 years ago
parent
commit
1003c2a105
  1. 23
      24Hour/Program.cs

23
24Hour/Program.cs

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

Loading…
Cancel
Save