Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Machine Name appears null on Docker (works fine in Windows) #39

Open
cilerler opened this issue Aug 9, 2020 · 0 comments
Open

Machine Name appears null on Docker (works fine in Windows) #39

cilerler opened this issue Aug 9, 2020 · 0 comments

Comments

@cilerler
Copy link

cilerler commented Aug 9, 2020

Using serilog-enrichers-environment v2.1.3 with FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim on docker

MachineName appears to be null, where the code below returns both inquiries with the correct value.

Console.WriteLine($"HOSTNAME: {Environment.GetEnvironmentVariable("HOSTNAME")}\nMACHINENAME: {Environment.MachineName}");

image

appsettings.json

	"Serilog": {
		"MinimumLevel": {
			"Default": "Debug"
		},
		"Using": [
			"Serilog.Sinks.Seq"
		],
		"WriteTo": [
			{
				"Name": "Seq",
				"Args": {
					"serverUrl": "http://localhost:5341"
				}
			}
		],
		"Enrich": [
			"FromLogContext",
			"WithMachineName",
			"WithThreadId",
			"WithProcessId"
		],
		"Properties": {
			"Configuration": "DEVELOPMENT",
			"ApplicationName": "Test"
		}

Program.cs

	public class Program
	{
		public static async Task Main(string[] args)
		{
			Console.WriteLine($"HOSTNAME: {Environment.GetEnvironmentVariable("HOSTNAME")}\nMACHINENAME: {Environment.MachineName}");

			await Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder(args)
					.UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
							.ReadFrom.Configuration(hostingContext.Configuration)
					)
					.ConfigureServices((hostContext, services) =>
					{
						services.AddMyService(hostContext.Configuration);
					})
					.RunConsoleAsync();
		}
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant