Use serilog for logging (support log to file)
Clean up
This commit is contained in:
parent
2de8d8ab86
commit
45947f0492
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
[ApiController]
|
||||
[Route("api/[controller]")]
|
||||
|
@ -1,7 +1,6 @@
|
||||
using SharedProject.Models;
|
||||
using SharedProject.Models.Responses;
|
||||
using Swan.Mapping;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
|
@ -1,7 +1,4 @@
|
||||
using SharedProject.Models;
|
||||
using SharedProject.Models.Responses;
|
||||
using Swan.Mapping;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using SharedProject.Models.Responses;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using SharedProject.Models.Requests;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using SharedProject.Models.Responses;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
|
@ -1,11 +1,6 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json;
|
||||
using SharedProject.Models;
|
||||
using SharedProject.Models.Responses;
|
||||
using SharedProject.Utils;
|
||||
using TaikoLocalServer.Services;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Api;
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
@ -164,7 +163,7 @@ public class BaidController : BaseController<BaidController>
|
||||
IsDispAchievementTypeSet = true,
|
||||
LastPlayMode = userData.LastPlayMode,
|
||||
IsDispSouuchiOn = true,
|
||||
AiRank = 0,
|
||||
AiRank = 1,
|
||||
AiTotalWin = (uint)totalWin,
|
||||
Accesstoken = "123456",
|
||||
ContentInfo = GZipBytesUtil.GetGZipBytes(new byte[10])
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/crownsdata.php")]
|
||||
[ApiController]
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/getaidata.php")]
|
||||
[ApiController]
|
||||
@ -24,7 +22,9 @@ public class GetAiDataController : BaseController<GetAiDataController>
|
||||
var response = new GetAiDataResponse
|
||||
{
|
||||
Result = 1,
|
||||
TotalWinnings = (uint)totalWin
|
||||
TotalWinnings = (uint)totalWin,
|
||||
InputMedian = "1000",
|
||||
InputVariance = "2000"
|
||||
};
|
||||
|
||||
return Ok(response);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/getdanodai.php")]
|
||||
[ApiController]
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/getdanscore.php")]
|
||||
[ApiController]
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/getscorerank.php")]
|
||||
[ApiController]
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/getsongintroduction.php")]
|
||||
[ApiController]
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[ApiController]
|
||||
[Route("/v12r03/chassis/initialdatacheck.php")]
|
||||
|
@ -1,7 +1,4 @@
|
||||
using TaikoLocalServer.Services;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
[Route("/v12r03/chassis/mydonentry.php")]
|
||||
[ApiController]
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
@ -1,5 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Buffers.Binary;
|
||||
using System.Text.Json;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Controllers.Game;
|
||||
|
@ -10,3 +10,5 @@ global using TaikoLocalServer.Common.Utils;
|
||||
global using TaikoLocalServer.Context;
|
||||
global using TaikoLocalServer.Entities;
|
||||
global using TaikoLocalServer.Models;
|
||||
global using TaikoLocalServer.Services;
|
||||
global using TaikoLocalServer.Services.Interfaces;
|
@ -1,87 +1,121 @@
|
||||
using System.Reflection;
|
||||
using System.Security.Authentication;
|
||||
using Microsoft.AspNetCore.HttpLogging;
|
||||
using Microsoft.AspNetCore.HttpOverrides;
|
||||
using TaikoLocalServer.Middlewares;
|
||||
using TaikoLocalServer.Services;
|
||||
using TaikoLocalServer.Services.Extentions;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using TaikoLocalServer.Settings;
|
||||
using Throw;
|
||||
using Serilog;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
// Manually enable tls 1.0
|
||||
builder.WebHost.UseKestrel(kestrelOptions =>
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.CreateBootstrapLogger();
|
||||
|
||||
var version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
||||
.InformationalVersion;
|
||||
Log.Information("TaikoLocalServer version {Version}", version);
|
||||
|
||||
Log.Information("Server starting up...");
|
||||
|
||||
try
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
// Manually enable tls 1.0
|
||||
builder.WebHost.UseKestrel(kestrelOptions =>
|
||||
{
|
||||
kestrelOptions.ConfigureHttpsDefaults(httpsOptions =>
|
||||
{
|
||||
httpsOptions.SslProtocols = SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13;
|
||||
httpsOptions.SslProtocols =
|
||||
SslProtocols.Tls | SslProtocols.Tls11 | SslProtocols.Tls12 | SslProtocols.Tls13;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddOptions();
|
||||
builder.Services.AddSingleton<IGameDataService, GameDataService>();
|
||||
builder.Services.Configure<UrlSettings>(builder.Configuration.GetSection(nameof(UrlSettings)));
|
||||
builder.Services.AddControllers().AddProtoBufNet();
|
||||
builder.Services.AddDbContext<TaikoDbContext>(option =>
|
||||
{
|
||||
builder.Host.UseSerilog((context, configuration) =>
|
||||
{
|
||||
configuration.WriteTo.Console().ReadFrom.Configuration(context.Configuration);
|
||||
});
|
||||
|
||||
// Add services to the container.
|
||||
builder.Services.AddOptions();
|
||||
builder.Services.AddSingleton<IGameDataService, GameDataService>();
|
||||
builder.Services.Configure<UrlSettings>(builder.Configuration.GetSection(nameof(UrlSettings)));
|
||||
builder.Services.AddControllers().AddProtoBufNet();
|
||||
builder.Services.AddDbContext<TaikoDbContext>(option =>
|
||||
{
|
||||
var dbName = builder.Configuration["DbFileName"];
|
||||
if (string.IsNullOrEmpty(dbName))
|
||||
{
|
||||
dbName = Constants.DEFAULT_DB_NAME;
|
||||
}
|
||||
|
||||
var path = Path.Combine(PathHelper.GetRootPath(), dbName);
|
||||
option.UseSqlite($"Data Source={path}");
|
||||
});
|
||||
builder.Services.AddHttpLogging(options =>
|
||||
{
|
||||
options.LoggingFields = HttpLoggingFields.RequestProperties |
|
||||
HttpLoggingFields.ResponseStatusCode;
|
||||
});
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("DevCorsPolicy", policy =>
|
||||
});
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy("AllowAllCorsPolicy", policy =>
|
||||
{
|
||||
policy
|
||||
.AllowAnyOrigin()
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader();
|
||||
});
|
||||
});
|
||||
builder.Services.AddTaikoDbServices();
|
||||
});
|
||||
builder.Services.AddTaikoDbServices();
|
||||
|
||||
var app = builder.Build();
|
||||
var app = builder.Build();
|
||||
|
||||
// Migrate db
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
// Migrate db
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<TaikoDbContext>();
|
||||
db.Database.Migrate();
|
||||
}
|
||||
}
|
||||
|
||||
var gameDataService = app.Services.GetService<IGameDataService>();
|
||||
gameDataService.ThrowIfNull();
|
||||
await gameDataService.InitializeAsync();
|
||||
app.UseSerilogRequestLogging(options =>
|
||||
{
|
||||
options.MessageTemplate = "HTTP {RequestMethod} {RequestPath} responded {StatusCode} in {Elapsed:0.0000} ms, " +
|
||||
"request host: {RequestHost}";
|
||||
options.EnrichDiagnosticContext = (diagnosticContext, httpContext) =>
|
||||
{
|
||||
diagnosticContext.Set("RequestHost", httpContext.Request.Host.Value);
|
||||
};
|
||||
});
|
||||
|
||||
// For reverse proxy
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
var gameDataService = app.Services.GetService<IGameDataService>();
|
||||
gameDataService.ThrowIfNull();
|
||||
await gameDataService.InitializeAsync();
|
||||
|
||||
// For reverse proxy
|
||||
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
||||
{
|
||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||
});
|
||||
});
|
||||
|
||||
app.UseCors("DevCorsPolicy");
|
||||
// For blazor hosting
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
app.UseCors("AllowAllCorsPolicy");
|
||||
// For blazor hosting
|
||||
app.UseBlazorFrameworkFiles();
|
||||
app.UseStaticFiles();
|
||||
app.UseRouting();
|
||||
|
||||
|
||||
app.UseHttpLogging();
|
||||
app.MapControllers();
|
||||
app.MapFallbackToFile("index.html");
|
||||
app.UseHttpLogging();
|
||||
app.MapControllers();
|
||||
app.MapFallbackToFile("index.html");
|
||||
|
||||
app.UseWhen(context => context.Request.Path.StartsWithSegments("/sys/servlet/PowerOn", StringComparison.InvariantCulture),
|
||||
app.UseWhen(
|
||||
context => context.Request.Path.StartsWithSegments("/sys/servlet/PowerOn", StringComparison.InvariantCulture),
|
||||
applicationBuilder => applicationBuilder.UseAllNetRequestMiddleware());
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Unhandled exception");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.Information("Shut down complete");
|
||||
Log.CloseAndFlush();
|
||||
}
|
@ -1,5 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
using SharedProject.Models;
|
||||
using Swan.Mapping;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
||||
public class DanScoreDatumService : IDanScoreDatumService
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Services.Extentions;
|
||||
namespace TaikoLocalServer.Services.Extentions;
|
||||
|
||||
public static class ServiceExtensions
|
||||
{
|
||||
|
@ -2,7 +2,6 @@
|
||||
using System.Text.Json;
|
||||
using SharedProject.Models;
|
||||
using Swan.Mapping;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
@ -1,6 +1,5 @@
|
||||
using SharedProject.Models;
|
||||
using Swan.Mapping;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
@ -1,6 +1,4 @@
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
||||
class SongPlayDatumService : ISongPlayDatumService
|
||||
{
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Text.Json;
|
||||
using TaikoLocalServer.Services.Interfaces;
|
||||
using Throw;
|
||||
|
||||
namespace TaikoLocalServer.Services;
|
||||
|
@ -4,6 +4,7 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Version>0.3.0-alpha</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -20,6 +21,8 @@
|
||||
</PackageReference>
|
||||
<PackageReference Include="protobuf-net" Version="3.1.17" />
|
||||
<PackageReference Include="protobuf-net.AspNetCore" Version="3.1.17" />
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="6.1.0-dev-00281" />
|
||||
<PackageReference Include="Serilog.Expressions" Version="3.4.1-dev-00095" />
|
||||
<PackageReference Include="SharpZipLib" Version="1.3.3" />
|
||||
<PackageReference Include="Swan.Core" Version="6.0.2-beta.90" />
|
||||
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.69" />
|
||||
|
@ -1,8 +0,0 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Information"
|
||||
}
|
||||
}
|
||||
}
|
@ -3,15 +3,36 @@
|
||||
"MuchaUrl": "https://v402-front.mucha-prd.nbgi-amnet.jp:10122",
|
||||
"GameUrl": "vsapi.taiko-p.jp"
|
||||
},
|
||||
|
||||
"DbFileName" : "taiko.db3",
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
|
||||
"Serilog": {
|
||||
"MinimumLevel": {
|
||||
"Default": "Information",
|
||||
"Override": {
|
||||
"Microsoft": "Warning",
|
||||
"Microsoft.AspNetCore": "Warning",
|
||||
"Microsoft.AspNetCore.HttpLogging.HttpLoggingMiddleware": "Information"
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"Filter": [
|
||||
{
|
||||
"Name": "ByExcluding",
|
||||
"Args": {
|
||||
"expression": "@mt = 'An unhandled exception has occurred while executing the request.'"
|
||||
}
|
||||
}
|
||||
],
|
||||
"WriteTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": { "path": "./Logs/log-.txt", "rollingInterval": "Day" }
|
||||
}
|
||||
]
|
||||
},
|
||||
|
||||
"AllowedHosts": "*",
|
||||
|
||||
"Kestrel": {
|
||||
"Endpoints": {
|
||||
"Server": {
|
||||
|
Loading…
Reference in New Issue
Block a user