Boost Your .NET Projects with Spargine: Unlocking the Power of the ComputerInfo Class

Spargine is a collection of open-source assemblies and NuGet packages designed for .NET 10, which I have been developing and maintaining since the release of .NET Framework 2. These assemblies are not only a core part of my projects but are also actively deployed in production environments across several companies I collaborate with.

Get Spargine

You can access the source code and NuGet packages here:

The ComputerInfo class — part of the DotNetTips.Spargine.Core assembly — provides a comprehensive set of properties for retrieving vital information about the system environment. I primarily use it for application logging and diagnostics, where reliable and structured runtime metadata is essential.

By consolidating information from multiple .NET APIs into a single type, ComputerInfo makes it easy to gather environment, OS, CPU, memory, and runtime details without scattering code across your project.

Properties

The ComputerInfo class exposes a wide range of properties designed to make working with system information straightforward. Here’s a detailed breakdown:

Culture & Thread Information

  • ComputerCulture
    Retrieves the computer’s culture in a three-letter ISO language format.
  • ComputerUICulture
    Returns the UI culture of the system in a three-letter ISO language format.
  • CurrentManagedThreadId
    Provides the identifier of the current managed thread.
  • CurrentStackTrace
    Captures the current stack trace.

System & Runtime Environment

  • CurrentSystemTickCount
    Returns the system’s tick count.
  • CurrentWorkingDirectory
    Shows the directory from which the current process is running.
  • FrameworkDescription
    Displays a description of the .NET runtime currently in use.
  • FrameworkVersion
    Retrieves the version of the .NET framework/runtime.
  • HasShutdownStarted
    Indicates whether the system shutdown process has begun.
  • Is64BitOperatingSystem
    Indicates whether the operating system is 64-bit.
  • Is64BitProcess
    Indicates whether the current process is 64-bit.
  • IsUserInteractive
    Shows whether the current process is running in a user-interactive session.
  • SystemDirectory
    Displays the system directory path.

CPU & Performance

  • ProcessorCount
    Indicates the number of processors available on the machine.
  • GetCpuUsagePrivilegedTime
    Gets the CPU privileged execution time — time spent executing kernel-mode operations such as hardware and system calls.
  • GetCpuUsageTotalTime
    Gets the total CPU usage time.
  • GetCpuUsageUserTime
    Gets the CPU time spent executing user-mode code.

Memory & Disk

  • DiskUsage
    Gets disk usage for the computer, including total size and total free space of all ready drives.
  • LogicalDrives
    Lists the logical drives available on the system.
  • OSMemoryPageSize
    Displays the memory page size of the OS.
  • PhysicalMemoryInUse
    Shows the current usage of physical memory.
  • SystemPageSize
    Provides the system page size.

OS & Platform

  • MachineName
    Retrieves the computer’s machine name.
  • OSArchitecture
    Returns the OS architecture (e.g., x64 or x86).
  • OSDescription
    Provides a description of the operating system.
  • ProcessArchitecture
    Returns the architecture of the current process.

Networking

  • IPAddresses
    Lists the IP addresses assigned to the computer.
  • IsNetworkAvailable
    Determines whether network connectivity is available by evaluating real (non-loopback, non-virtual) interfaces.
  • UserDomainName
    Displays the domain name associated with the current user.
  • UserName
    Retrieves the name of the current user.

System Timing

  • TickCount
    Returns the system tick count.
  • TickCount64
    Returns the system tick count as a 64-bit value.
  • Uptime
    Indicates how long the system has been running.
  • Output Helpers
  • ToJson()
    Converts the current instance to a JSON string.
  • ToString()
    Returns a string representation of the current instance, including all property values.

Utility and Convenience

ComputerInfo consolidates information normally retrieved from Environment, RuntimeInformation, and other .NET APIs into a single, serializable object — ideal for diagnostics, telemetry, audit logging, and debugging.

Instead of manually querying multiple APIs, you simply create an instance and log its values. This reduces boilerplate, improves consistency, and ensures you never miss critical environment details.

Example Output

Here is a sample (trimmed) output from ToString():

ComputerInfo.GetCpuUsageTotalTime: 00:00:00.5468750
ComputerInfo.GetCpuUsageUserTime: 00:00:00.4687500
ComputerInfo.ComputerCulture: eng
ComputerInfo.ComputerUICulture: eng
ComputerInfo.CurrentManagedThreadId: 4
ComputerInfo.CurrentSystemTickCount: 3664718
ComputerInfo.CurrentWorkingDirectory: D:\src\GitHub\dotNetTips.Spargine.10\AppBin\net10.0
ComputerInfo.DiskUsage: 3,500,654,788,608 bytes free of 4,000,151,756,800 bytes
ComputerInfo.FrameworkDescription: .NET 10.0.1
ComputerInfo.FrameworkVersion: 10.0.1
ComputerInfo.GetCpuUsagePrivilegedTime: 00:00:00.0781250
ComputerInfo.HasShutdownStarted: False
ComputerInfo.IPAddress: 192.168.1.858
ComputerInfo.Is64BitOperatingSystem: True
ComputerInfo.Is64BitProcess: True
ComputerInfo.IsNetworkAvailable: True
ComputerInfo.IsUserInteractive: True
ComputerInfo.LogicalDrives: C:\, D:\, E:\
ComputerInfo.MachineName: DESKTOP-DOTNETDAVE
ComputerInfo.OSArchitecture: X64
ComputerInfo.OSDescription: Microsoft Windows 10.0.19045
ComputerInfo.OSMemoryPageSize: 4096
ComputerInfo.PhysicalMemoryInUse: 58994688
ComputerInfo.ProcessorCount: 12
ComputerInfo.SystemDirectory: C:\WINDOWS\system32
ComputerInfo.SystemPageSize: 4096
ComputerInfo.TickCount: 3664734
ComputerInfo.TickCount64: 3664734
ComputerInfo.Uptime: 01:01:04.8900000
ComputerInfo.UserDomainName: DESKTOP-DOTNETDAVE
ComputerInfo.UserName: dotnetdave

This makes structured logging extremely easy.

Future Enhancements

If you have suggestions for additional properties or improvements to the ComputerInfo class, feel free to submit an issue or feature request on GitHub. Community-driven evolution is one of the biggest strengths of Spargine.

Summary

The ComputerInfo class delivers a powerful, centralized, and developer-friendly way to retrieve and log environment and system metadata in .NET applications. By eliminating the need to manually gather this information from multiple APIs, it simplifies diagnostics, improves observability, and increases reliability across your applications.

Get Involved!

The success of open-source projects like Spargine relies on community contributions. If you find these updates useful or have ideas for further improvements, I encourage you to contribute by:

  • Submitting pull requests
  • Reporting issues
  • Suggesting new features

Your input is invaluable in making Spargine an even more powerful tool for the .NET community.

If you are interested in contributing or have any questions, feel free to contact me via email at dotnetdave@live.com. Your support and collaboration are greatly appreciated!

Thank you, and happy coding!

Pick up any books by David McCarter by going to Amazon.com: http://bit.ly/RockYourCodeBooks

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

If you liked this article, please buy David a cup of Coffee by going here: https://www.buymeacoffee.com/dotnetdave

© The information in this article is copywritten and cannot be preproduced in any way without express permission from David McCarter.


Discover more from dotNetTips.com

Subscribe to get the latest posts sent to your email.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.