-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
427d588
commit 3359c75
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Hosting; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace CSGO_DataLogger.controllers | ||
{ | ||
[ApiController] | ||
[Route("Log")] | ||
public class LogController : ControllerBase | ||
{ | ||
private readonly ILogger _logger; | ||
private readonly ConfigCache _configCache; | ||
private readonly LogManager _logManager; | ||
|
||
public LogController(ILogger<LogController> logger,ConfigCache configCache, LogManager logManager) | ||
{ | ||
_logger = logger; | ||
_configCache = configCache; | ||
_logManager = logManager; | ||
} | ||
|
||
[HttpPost] | ||
[Route("Log")] | ||
//[ReadableBodyStream] | ||
public async Task Log(CancellationToken cancellationToken) | ||
{ | ||
string lines = await StreamToStringAsync(Request); | ||
foreach (string line in lines.Split('\n')) | ||
{ | ||
if (_configCache.Debug) | ||
{ | ||
_logger.LogInformation($"Recieved: {line}"); | ||
Task.Run(() => _logManager.ParseLog(Request.HttpContext.Connection.RemoteIpAddress?.ToString() ?? "Unknown", line, cancellationToken)); | ||
} | ||
} | ||
} | ||
|
||
private async Task<string> StreamToStringAsync(HttpRequest request) | ||
{ | ||
using (var sr = new StreamReader(request.Body)) | ||
{ | ||
return await sr.ReadToEndAsync(); | ||
} | ||
} | ||
} | ||
} |