0

Is there a way to log the Windows version and the MAC address (or some other type of unique machine ID) using Nlog in C#? The logger would be running on windows desktop PCs.

Abhishek Bhagate
  • 5,583
  • 3
  • 15
  • 32
Charlie P
  • 51
  • 2
  • 8
  • If you can _get_ both in a C# program, you can _log_ both, yes. Or do you mean in a layout renderer? – Fildor Jul 15 '20 at 11:55
  • See [Environment.OSVersion Property](https://learn.microsoft.com/en-us/dotnet/api/system.environment.osversion?view=netcore-3.1), [Reliable method to get machine's MAC address in C#](https://stackoverflow.com/q/850650/982149) – Fildor Jul 15 '20 at 11:57
  • 1
    @Fildor Thanks for the info. I was curious how I may add that info (Windows version and MAC address) in the layout renderer. – Charlie P Jul 16 '20 at 12:27

1 Answers1

4

Nlog has some layout renderers you can try:

  • ${environment} - The environment variable. (e.g PATH, OSVersion)
  • ${machinename} - The machine name that the process is running on.
  • ${hostname} - The host name of the computer that the process is running on.

You can add them to layout= attribute of corresponding target.

Guru Stron
  • 102,774
  • 10
  • 95
  • 132