You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.5 KiB
59 lines
2.5 KiB
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Serilog;
|
|
using Serilog.Core;
|
|
using Serilog.Events;
|
|
using System;
|
|
using System.IO;
|
|
using System.Threading;
|
|
|
|
namespace TestServer
|
|
{
|
|
public class Program
|
|
{
|
|
private static CancellationTokenSource cts = new CancellationTokenSource();
|
|
|
|
public static void Main(string[] args)
|
|
{
|
|
Log.Logger = new LoggerConfiguration()
|
|
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
|
.MinimumLevel.Debug()
|
|
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "logs", "app.log.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Information))
|
|
.WriteTo.File(Path.Combine(Directory.GetCurrentDirectory(), "logs", "app.err.txt"), shared: true, rollOnFileSizeLimit: true, fileSizeLimitBytes: 1024 * 1024 * 1024, rollingInterval: RollingInterval.Day, retainedFileCountLimit: 7, levelSwitch: new LoggingLevelSwitch(LogEventLevel.Error))
|
|
.CreateLogger();
|
|
try
|
|
{
|
|
while(!cts.IsCancellationRequested)
|
|
{
|
|
Log.Information("server start");
|
|
Host.CreateDefaultBuilder(args)
|
|
.UseSerilog()
|
|
.ConfigureWebHostDefaults(webBuilder =>
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|
.AddJsonFile("appsettings.json", optional: false)
|
|
.Build();
|
|
webBuilder.UseUrls(config.GetValue("server.urls", "http://*:9505"));
|
|
webBuilder.CaptureStartupErrors(true);
|
|
webBuilder.UseSetting(WebHostDefaults.DetailedErrorsKey, "true");
|
|
webBuilder.UseStartup<Startup>();
|
|
})
|
|
.Build()
|
|
.Run();
|
|
Log.Information("server exit");
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex.ToString());
|
|
}
|
|
finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
}
|
|
} |