serilog / serilog-enrichers-environment

Enrich Serilog log events with properties from System.Environment.
Apache License 2.0
79 stars 33 forks source link

Handling null machine names #21

Closed dasjestyr closed 6 years ago

dasjestyr commented 7 years ago

So when this enricher is run on a linux machine, it outputs "null" in place of the machine name. I think if the machine name isn't able to be obtained, something less obtrusive should be returned such as an empty string.

nblumhardt commented 7 years ago

Even leaving the property off entirely could work 👍

drch- commented 7 years ago

Why not simply Environment.MachineName ?? Works on mac/linux in dotnetcore as well.

nblumhardt commented 7 years ago

@drch- good point! I think when this package was written, Environment.MachineName wasn't present in .NET Core, but it seems like it made it in for the 1.0 (at least according to the docs). We should try to switch the package across 👍

syska commented 6 years ago

@nblumhardt

Well ... issue already here.

Both COMPUTERNAME and HOSTNAME is empty or null on my Linux Ubuntu 16.04.

But System.Environment.MachineName is present with the right hostname on dotnetcore2

Could be fun to try and do a pull request. :-)

But what should the logic be here? Do we want backward compability here? So just add the third option to try and keep the two others? Could there be some Mono issues with this?

From the property I can see this: /// The name of this computer cannot be obtained.

nblumhardt commented 6 years ago

@syska thanks for the information. I think just switching to Environment.MachineName would be the way to go 👍

MaikuMori commented 6 years ago

There is also the quickfix - the correct env variable to look for on Linux is $HOST instead of $HOSTNAME. At least for this purpose.

sven-s commented 6 years ago

As a workaround you can set

Environment.SetEnvironmentVariable("HOSTNAME", Environment.MachineName);

before calling the enricher.