Embed Management Information and Events

Windows exposes a great deal of system information through WMI (Windows Management Instrumentation). The 70-536 exam measures your capabilities to query WMI, subscribe to events, etc. Not the names of different WMI types (although I have seen test questions about those, but they could be figured out by pure logic).

To access WMI, you’ll need to set a reference on the System.Management namespace, and include a using directive for it. Then the following steps:
Continue reading “Embed Management Information and Events”

Embed Configuration Management Functionality

You have to choices to store application data when working with the .NET Framework. The first opportunity is to hard-code it, the second is to use external, XML-based configuration files. The .NET Framework has a whole hierarchy of these files. On the top of it lives the machine.config. This configuration file is machine-wide, all managed applications refer to it.

When you are working with web applications, the hierarchy can have numerous levels. For standard (desktop) applications, there’s only one more level, the application configuration file of the current program. This typically has the name of TheApplicationName.exe.config.

First, let’s set out the rules. If you’d like to read from a configuration file from your code, you’ll require rights for reading all configuration files which plays a role in your application, back to machine.config. To modify configuration files from code, you’ll need the reading rights mentioned before, and writing rights to the application’s configuration file.

Continue reading “Embed Configuration Management Functionality”

Debug and Trace a .NET Application

Debugging and tracing are both enables you to log information about your application’s health, current status, etc. The main difference is that debugging is only allowed (it runs only) in debug mode. You can define a debug mode by adding the #define DEBUG command at the top of your code (or compiling your code with the /d:DEBUG flag.

We’ll cover the following classes and attributes in this post:

  • Debug
  • Debugger
  • Debugger Attributes
    • DebuggerBrowsable
    • DebuggerDisplay
    • DebuggerHidden
    • DebuggerNonUserCode
    • DebuggerStepThrough
    • DebuggerTypeProxy
  • Trace
  • TraceListener
    • EventLogTraceListener
    • XmlWriterTraceListener
    • DelimitedListTraceListener

Continue reading “Debug and Trace a .NET Application”

Performance Counters

Performance counters helps you monitor the status of a given application, and identify bottlenecks. You can view performance counters in the Computer Management tool, by selecting the Performance (or Reliability &Performance) tab.

To access performance counters programmatically, you’ll use the PerformanceCounter class. To read from an existing counter, use the following method:

PerformanceCounter pc = new PerformanceCounter(“Processor”, “% Processor Time”, “_Total”);
pc.NextValue();
Thread.Sleep(1000);
Console.WriteLine(pc.NextValue);

Continue reading “Performance Counters”

System Processes

To work with system processes, either local or remote ones, you should use the System.Diagnostics namespace’s Process class. I wouldn’t waste time on describing processes, let’s see what are the objectives here:

  • Get a list of running processes
  • Retrieve information about the current process
  • Get a list of modules loaded by a process
  • Start a process by using and not using command-line arguments

Continue reading “System Processes”

Manage an Event Log

Event logs are the best friends of a system administrator. When some unhandled exception occurs, or system failure, etc. you should write it to the event log, so the information won’t be lost later. You can access event logs by clicking the Manage button on the Computer. Then you should select the Event Viewer pane.

There are three categories of events: System, Security and Application. Forget the former two, you’ll only need to (and are able to) work with the Application event log.

All event log related classes live in the System.Diagnostics namespace. The most important types here:

  • EventLog
  • EventLogEntry
  • EventLogEntryCollection
  • EventLogEntryType
  • EventLogPermission
  • EventLogTraceListener
  • EventSourceCreationData

Continue reading “Manage an Event Log”