1
0
mirror of synced 2024-11-27 16:10:53 +01:00

Add writing headClerk2 request info to csv log files

This commit is contained in:
S-Sebb 2023-10-14 23:11:21 +01:00
parent 614b693760
commit d179ff4a4e
5 changed files with 99 additions and 12 deletions

View File

@ -9,6 +9,26 @@ public class Headclerk2Controller : BaseController<Headclerk2Controller>
public IActionResult Headclerk2([FromBody] HeadClerk2Request request) public IActionResult Headclerk2([FromBody] HeadClerk2Request request)
{ {
Logger.LogInformation("Headclerk2 request: {Request}", request.Stringify()); Logger.LogInformation("Headclerk2 request: {Request}", request.Stringify());
var chassisId = request.ChassisId;
var shopId = request.ShopId;
foreach (var playInfo in request.AryPlayInfoes)
{
var baid = playInfo.Baid;
var playedAt = playInfo.PlayedAt;
var isRight = playInfo.IsRight;
var type = playInfo.Type;
var amount = playInfo.Amount;
Logger.LogInformation("CSV WRITE: \n" +
"ChassisId:{ChassisId},\n" +
"ShopId:{ShopId},\n" +
"Baid:{Baid},\n" +
"PlayedAt{PlayedAt},\n" +
"IsRight:{IsRight},\n" +
"Type:{Type},\n" +
"Amount{Amount}", chassisId, shopId, baid, playedAt, isRight, type, amount);
}
var response = new HeadClerk2Response var response = new HeadClerk2Response
{ {
Result = 1 Result = 1

View File

@ -0,0 +1,20 @@
namespace TaikoLocalServer.Controllers.Game;
[Route("/v12r00_cn/chassis/setanystring.php")]
[ApiController]
public class SetAnyStringController : BaseController<SetAnyStringController>
{
[HttpPost]
[Produces("application/protobuf")]
public IActionResult SetAnyString([FromBody] SetAnyStringRequest request)
{
Logger.LogInformation("SetAnyString request : {Request}", request.Stringify());
var response = new SetAnyStringResponse
{
Result = 1,
};
return Ok(response);
}
}

View File

@ -0,0 +1,35 @@
using Serilog.Events;
using Serilog.Formatting;
namespace TaikoLocalServer.Logging;
public class CsvFormatter: ITextFormatter
{
public void Format(LogEvent logEvent, TextWriter output)
{
logEvent.Properties.TryGetValue("ChassisId", out var chassisId);
logEvent.Properties.TryGetValue("ShopId", out var shopId);
logEvent.Properties.TryGetValue("Baid", out var baid);
logEvent.Properties.TryGetValue("PlayedAt", out var playedAt);
logEvent.Properties.TryGetValue("IsRight", out var isRight);
logEvent.Properties.TryGetValue("Type", out var type);
logEvent.Properties.TryGetValue("Amount", out var amount);
output.Write(logEvent.Timestamp.ToString("yyyy-MM-dd"));
output.Write(",");
output.Write(chassisId);
output.Write(",");
output.Write(shopId);
output.Write(",");
output.Write(baid);
output.Write(",");
output.Write(playedAt);
output.Write(",");
output.Write(isRight);
output.Write(",");
output.Write(type);
output.Write(",");
output.Write(amount);
output.WriteLine();
}
}

View File

@ -1,5 +1,7 @@
using System.Reflection; using System.Reflection;
using System.Security.Authentication; using System.Security.Authentication;
using Serilog.Sinks.File.Header;
using TaikoLocalServer.Logging;
using GameDatabase.Context; using GameDatabase.Context;
using Microsoft.AspNetCore.HttpLogging; using Microsoft.AspNetCore.HttpLogging;
using Microsoft.AspNetCore.HttpOverrides; using Microsoft.AspNetCore.HttpOverrides;
@ -40,7 +42,16 @@ try
builder.Host.UseSerilog((context, configuration) => builder.Host.UseSerilog((context, configuration) =>
{ {
configuration.WriteTo.Console().ReadFrom.Configuration(context.Configuration); configuration
.WriteTo.Console().ReadFrom.Configuration(context.Configuration)
.WriteTo.Logger(x =>
{
x.WriteTo.File(new CsvFormatter(),
path: "./Logs/HeadClerkLog-.csv",
hooks: new HeaderWriter("Date,ChassisId,ShopId,Baid,PlayedAt,IsRight,Type,Amount"),
rollingInterval: RollingInterval.Day);
x.Filter.ByIncludingOnly("StartsWith(@m, 'CSV WRITE:')");
});
}); });
if (builder.Configuration.GetValue<bool>("ServerSettings:EnableMoreSongs")) if (builder.Configuration.GetValue<bool>("ServerSettings:EnableMoreSongs"))

View File

@ -25,6 +25,7 @@
<PackageReference Include="protobuf-net.AspNetCore" Version="3.2.12" /> <PackageReference Include="protobuf-net.AspNetCore" Version="3.2.12" />
<PackageReference Include="Serilog.AspNetCore" Version="7.0.0" /> <PackageReference Include="Serilog.AspNetCore" Version="7.0.0" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0-dev-00137" /> <PackageReference Include="Serilog.Expressions" Version="4.0.0-dev-00137" />
<PackageReference Include="Serilog.Sinks.File.Header" Version="1.0.2" />
<PackageReference Include="SharpZipLib" Version="1.4.2" /> <PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="Swan.Core" Version="7.0.0-beta.2" /> <PackageReference Include="Swan.Core" Version="7.0.0-beta.2" />
<PackageReference Include="Swan.Logging" Version="6.0.2-beta.96" /> <PackageReference Include="Swan.Logging" Version="6.0.2-beta.96" />