修改日志

master
hang 2024-01-26 13:18:10 +08:00
parent 3f8b709446
commit 6c8244d36c
3 changed files with 20 additions and 21 deletions

View File

@ -50,6 +50,10 @@
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.2.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NLog.Web.AspNetCore" Version="4.9.3" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="5.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="5.1.2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.5.1" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.5.1" />

View File

@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NLog.Web;
using Serilog;
namespace IRaCIS.Core.API
{
@ -12,24 +13,11 @@ namespace IRaCIS.Core.API
{
public static void Main(string[] args)
{
ImageManager.SetImplementation(WinFormsImageManager.Instance);
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
try
{
logger.Debug("init main");
ImageManager.SetImplementation(WinFormsImageManager.Instance);
CreateHostBuilder(args).Build().Run();
}
catch (Exception exception)
{
//NLog: catch setup errors
logger.Error(exception, "Stopped program because of exception");
throw;
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
NLog.LogManager.Shutdown();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
@ -38,20 +26,19 @@ namespace IRaCIS.Core.API
{
webBuilder.ConfigureKestrel((context, options) =>
{
//设置应用服务器Kestrel请求体最大为1GB // if don't set default value is: 30 MB
//设置应用服务器Kestrel请求体最大为1GB // if don't set default value is: 30 MB
options.Limits.MaxRequestBodySize = long.MaxValue;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(30);
options.Limits.RequestHeadersTimeout = TimeSpan.FromMinutes(30);
});
webBuilder.UseStartup<Startup>();
})//使用Autofac替代本身容器
})//使用Autofac替代本身容器
.UseServiceProviderFactory(new AutofacServiceProviderFactory()).
ConfigureLogging(logging =>
{
logging.ClearProviders();
logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
})
.UseNLog()
}).UseSerilog()
; // NLog: Setup NLog for Dependency injection;
}

View File

@ -17,6 +17,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Serilog;
using System;
using System.IO;
using System.Reflection;
@ -114,6 +115,11 @@ namespace IRaCIS.Core.API
// options.MaxRequestBodySize = int.MaxValue;
//});
Log.Logger = new LoggerConfiguration()
.WriteTo.Console() // 选择日志输出目标,可以选择文件、数据库等
.CreateLogger();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -162,6 +168,8 @@ namespace IRaCIS.Core.API
{
endpoints.MapControllers();
});
Log.Information("计费系统启动...");
}
}
}