lloyd lloyd - 9 months ago 79
C# Question

How To Get Server Machine Identifier?

I have multiple machines for each DEV, QA, and Production. I need to implement a solution of finding the host machine's identity with the intent of eventually integrating it into some common library dll.

On some older applications that I have, errors are sometimes generated but it is not clear which machine this is coming from and obviously it becomes an issue when some automatically generated error is created without knowing the environment.

In my current situation I'm only allowed to modify the error message input into the log generator, and not any internals beyond that.

With that given I need some code that returns a

string
that identifies the machine that throws some exception. Is there some C# Method / Type / Library that I can look into?

Example code would be nice, but really I'm just looking for a starting point. Methods I've tried with identity have only caused the build to fail to deploy from my build machine to my DEV server.

Answer Source

You can use System.Environment.MachineName to get the current computer's name.

You just need to make sure the machine name provides you with enough information. If it doesn't and you have a Domain, you can probably add some information about each machine in the Active Directory, and fetch it from there.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download