-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Log to file Add correlation vector to logs Add IP to logs Add API Key to logs
- Loading branch information
1 parent
8399cc6
commit f93b177
Showing
22 changed files
with
238 additions
and
77 deletions.
There are no files selected for viewing
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
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
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
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
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
24 changes: 24 additions & 0 deletions
24
GuildWarsPartySearch/Middleware/CorrelationVectorMiddleware.cs
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,24 @@ | ||
| ||
using GuildWarsPartySearch.Server.Extensions; | ||
using Microsoft.CorrelationVector; | ||
|
||
namespace GuildWarsPartySearch.Server.Middleware; | ||
|
||
public sealed class CorrelationVectorMiddleware : IMiddleware | ||
{ | ||
private const string CorrelationVectorHeader = "X-Correlation-Vector"; | ||
|
||
public Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
{ | ||
var cv = new CorrelationVector(); | ||
if (context.Items.TryGetValue(CorrelationVectorHeader, out var correlationVectorVal) && | ||
correlationVectorVal is string correlationVectorStr) | ||
{ | ||
cv = CorrelationVector.Parse(correlationVectorStr); | ||
cv.Increment(); | ||
} | ||
|
||
context.SetCorrelationVector(cv); | ||
return next(context); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
GuildWarsPartySearch/Middleware/LoggingEnrichmentMiddleware.cs
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,18 @@ | ||
using GuildWarsPartySearch.Server.Extensions; | ||
using Serilog.Context; | ||
|
||
namespace GuildWarsPartySearch.Server.Middleware; | ||
|
||
public sealed class LoggingEnrichmentMiddleware : IMiddleware | ||
{ | ||
public Task InvokeAsync(HttpContext context, RequestDelegate next) | ||
{ | ||
var ip = context.GetClientIP(); | ||
var apiKey = context.GetApiKey(); | ||
var cv = context.GetCorrelationVector(); | ||
LogContext.PushProperty("ApiKey", apiKey); | ||
LogContext.PushProperty("ClientIP", ip); | ||
LogContext.PushProperty("CorrelationVector", cv); | ||
return next(context); | ||
} | ||
} |
Oops, something went wrong.