forked from Raphael/SCHALE.GameServer
93 lines
3.0 KiB
C#
93 lines
3.0 KiB
C#
using Microsoft.AspNetCore.Server.Kestrel.Core;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json;
|
|
using SCHALE.Common.NetworkProtocol;
|
|
using SCHALE.GameServer.Services;
|
|
using Serilog;
|
|
using Serilog.Events;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace SCHALE.GameServer
|
|
{
|
|
public class GameServer
|
|
{
|
|
public static async Task Main(string[] args)
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.SetBasePath(Path.GetDirectoryName(AppContext.BaseDirectory)!)
|
|
.AddJsonFile("appsettings.json")
|
|
.AddJsonFile(
|
|
$"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json",
|
|
true
|
|
)
|
|
.AddJsonFile("appsettings.Local.json", true)
|
|
.Build();
|
|
|
|
{
|
|
var logFilePath = Path.Combine(
|
|
Path.GetDirectoryName(AppContext.BaseDirectory)!,
|
|
"logs",
|
|
"log.txt"
|
|
);
|
|
|
|
if (File.Exists(logFilePath))
|
|
{
|
|
var prevLogFilePath = Path.Combine(
|
|
Path.GetDirectoryName(logFilePath)!,
|
|
"log-prev.txt"
|
|
);
|
|
if (File.Exists(prevLogFilePath))
|
|
File.Delete(prevLogFilePath);
|
|
|
|
File.Move(logFilePath, prevLogFilePath);
|
|
}
|
|
|
|
Log.Logger = new LoggerConfiguration()
|
|
.WriteTo.Console()
|
|
.WriteTo.File(
|
|
logFilePath,
|
|
restrictedToMinimumLevel: LogEventLevel.Verbose,
|
|
shared: true
|
|
)
|
|
.ReadFrom.Configuration(config)
|
|
.CreateBootstrapLogger();
|
|
}
|
|
|
|
Log.Information("Starting...");
|
|
try
|
|
{
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
builder.Services.Configure<KestrelServerOptions>(op =>
|
|
op.AllowSynchronousIO = true
|
|
);
|
|
builder.Host.UseSerilog();
|
|
|
|
// Add services to the container.
|
|
builder.Services.AddControllers();
|
|
|
|
builder.Services.AddHttpClient<PrivateClientService>();
|
|
builder.Services.AddSingleton<PrivateClientService>();
|
|
builder.Services.AddPrivateClientService();
|
|
|
|
var app = builder.Build();
|
|
|
|
// Configure the HTTP request pipeline.
|
|
app.UseAuthorization();
|
|
app.UseSerilogRequestLogging();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|
|
} catch (Exception ex)
|
|
{
|
|
Log.Fatal(ex, "An unhandled exception occurred during runtime");
|
|
} finally
|
|
{
|
|
Log.CloseAndFlush();
|
|
}
|
|
}
|
|
}
|
|
}
|