Skip to content

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

Open
@cilerler

Description

@cilerler

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();
		}
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions