Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.
I recently wrote a simple class for generating diagnostic information that should prove useful in tracking down errors when the system goes live. It details the operating system and .NET version installed on the current machine, the version and location of the entry assembly and the currently logged in OS user:
ENTRY ASSEMBLY--------------
File : C:\Projects\SystemDiagnosticDemo\SystemDiagnosticDemo\bin\Debug\SystemDiagnosticDemo.exeFileVersion : 1.0.0.123Product : SystemDiagnosticDemoProductVersion : 1.0.0.123
SERVER------
Machine Name : STUART-LAPTOPOperating System : Microsoft Windows NT 5.1.2600 Service Pack 2Processor Count : 1.NET Version : 2.0.50727.42OS User : STUART-LAPTOP\Stuart
As part of the automated build, the nant script creates an AssemblyInfo.cs file containing the Cruisecontrol build number. Cruisecontrol is also setup to tag the source code in Subversion with the same build number to give us full traceability. This means we can determine the exact source code that went into a particular dll and bring up the build log containing the unit test results.
The assembly metadata is retrieved using System.Diagnostics.FileVersionInfo.GetVersionInfo() method on the entry assembly file's location:
Assembly assembly = Assembly.GetEntryAssembly();string assemblyFileName = assembly.Location;FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(assemblyFileName);string fileName = versionInfo.FileName;string fileVersion = versionInfo.FileVersion;string product = versionInfo.ProductName;string productVersion = versionInfo.ProductVersion;
and the environment information comes from the static properties on the System.Environment class:
string machineName = Environment.MachineName;string operatingSystem = Environment.OSVersion.ToString();int processorCount = Environment.ProcessorCount;string dotNetVersion = Environment.Version.ToString();string osUser = String.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName);
The demo source code is available here: