Getting container id is important for logging. Let's get it.
- Add NuGet package
dotnet add package CodeWithSaar.Extensions.ContainerId --prerelease
- Put container id in your telemetry
// Get container id.
string containerId = await ContainerService.GetContainerIdAsync();
// Log it.
_logger.LogInformation("This is some information from container: {containerId}", containerId);
- Output:
info: TestClass[0] This is some information from container: 01d1ad1a7b528295f2d03619b35f995be9ddddcfd2a83c013df129aa6cc4d332
That's it. Start this repo if you like it.
Alternatively, dependency injection is also supported, refer to Use it with dependency injection.