-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve CorrelationId to use a static AsyncLocal string.
- Loading branch information
1 parent
2693028
commit 9e248fa
Showing
11 changed files
with
89 additions
and
48 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
28 changes: 28 additions & 0 deletions
28
src/shared/PlantBasedPizza.Shared/Logging/CorrelationContext.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,28 @@ | ||
namespace PlantBasedPizza.Shared.Logging; | ||
|
||
public static class CorrelationContext | ||
{ | ||
private static readonly AsyncLocal<string> _correlationId = new AsyncLocal<string>(); | ||
|
||
public static string DefaultRequestHeaderName = "X-Correlation-ID"; | ||
|
||
public static void SetCorrelationId(string correlationId) | ||
{ | ||
if (string.IsNullOrWhiteSpace(correlationId)) | ||
{ | ||
throw new ArgumentException("Correlation Id cannot be null or empty", nameof(correlationId)); | ||
} | ||
|
||
if (!string.IsNullOrWhiteSpace(_correlationId.Value)) | ||
{ | ||
throw new InvalidOperationException("Correlation Id is already set for the context"); | ||
} | ||
|
||
_correlationId.Value = correlationId; | ||
} | ||
|
||
public static string GetCorrelationId() | ||
{ | ||
return _correlationId.Value; | ||
} | ||
} |
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