Skip to content

Commit

Permalink
Nieuwere path met minder hard coding
Browse files Browse the repository at this point in the history
  • Loading branch information
safouuwa committed Dec 6, 2024
1 parent 8e7791c commit 4c12471
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions C#api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@
{
await next.Invoke();
var path = context.Request.Path.Value;
var filepath = Path.Combine(Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).FullName).FullName).FullName).FullName, "C#api/RequestLogs/RequestLogs.txt").Replace('\\', '/');
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
string logFilePath = Path.GetFullPath(Path.Combine(baseDirectory, "..", "..", "..", "C#api", "RequestLogs", "RequestLogs.txt"));
var pathParts = path.Split('/', StringSplitOptions.RemoveEmptyEntries);

if (pathParts.Length > 2 && new[] { "transfers", "shipments", "orders", "items" }.Contains(pathParts[2]))
{
var user = AuthProvider.GetUser(context.Request.Headers["API_KEY"]);
if (user == null) return;
await File.AppendAllTextAsync(filepath, $"{context.Request.Method} {context.Request.Path} made by {user.App}; Model: {pathParts[2]}; StatusCode: {context.Response.StatusCode}; Date and Time: {DateTime.UtcNow.AddHours(1)}\n");
await File.AppendAllTextAsync(logFilePath, $"{context.Request.Method} {context.Request.Path} made by {user.App}; Model: {pathParts[2]}; StatusCode: {context.Response.StatusCode}; Date and Time: {DateTime.UtcNow.AddHours(1)}\n");
}
});

Expand Down

0 comments on commit 4c12471

Please sign in to comment.