.NET Development Foundation | |
---|---|
Exam objective:Embedding configuration, diagnostic, management, and installation features into a .NET Framework application
Configuration management is used here in a restricted sense. It refers to the adaptation of an application to a specific execution environment or user. This is usually done thru the use of configuration files that specify the run time parameters of the application. The typical example of such configuration information is the connection string used to locate and connect to the application database. The exam objectives are all related to the actual interaction of the application with its configuration files.
The management or the design of the configuration files themselves is a vast subject that is not touched by the exam objectives so we will not cover it in this study guide.
![]() |
MSDN's definition is "Windows event logs allow your applications and components to record information about important events. You can use these records to audit access to your system, troubleshoot problems, and re-create usage patterns"
For a general discussion seeMSDN
For specifics on the EventLog class and some cautions about its use seeMSDN
Windows Management Instrumentation -MSDN
![]() | Wikipedia has related information atWindows Management Instrumentation |
![]() | To do: |
Exam objective:Embed configuration management functionality into a .NET Framework application.
(Refer System.Configuration namespace)
Configuration class and ConfigurationManager class
ConfigurationSettings class, ConfigurationElement class, ConfigurationElementCollection class, and ConfigurationElementProperty class
Implement IConfigurationSectionHandler interface -MSDN
ConfigurationSection class, ConfigurationSectionCollection class, ConfigurationSectionGroup class, and ConfigurationSectionGroupCollection class
Implement ISettingsProviderService interface -MSDN
Implement IApplicationSettingsProvider interface -MSDN
ConfigurationValidationBase class -MSDN
Implement IConfigurationSystem interface -MSDN
Exam objective:Create a custom Microsoft Windows Installer for .NET Framework components by using the System.Configuration.Install namespace, and configure the .NET Framework applications by using configuration files, environment variables, and the .NET Framework Configuration tool (Mscorcfg.msc).
Installer class -MSDN
Configure which runtime version a .NET Framework application should use -MSDN
Configure where the runtime should search for an assembly -MSDN
Configure the location of an assembly and which version of the assembly to use -MSDN andMSDN
Direct the runtime to use the DEVPATH environment variable when searching for assemblies -MSDN
AssemblyInstaller class -MSDN
ComponentInstaller class -MSDN
Configure a .NET Framework application by using the .NET Framework Configuration tool (Mscorcfg.msc) -MSDN
ManagedInstaller class -MSDN
InstallContext class -MSDN
InstallerCollection class -MSDN
Implement IManagedInstaller interface -MSDN
InstallEventHandler delegate -MSDN
Configure concurrent garbage collection -MSDN
Register remote objects by using configuration files -MSDN
Exam objective:Manage an event log by using the System.Diagnostics namespace
EventLog class -MSDN
EventSourceCreationData class -MSDN
You create an EventLog by creating the first event source that writes to that log.
The two simplest way to do this are:
Note that there is no "EventSource" class in the System.Diagnostics namespace even though an object representing the source is created in the registry.
C# EventLog creation Example
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace EventLogLab1 { class Program { static void Main(string[] args) { try { EventLog log1 = new EventLog("EvtLab2Log"); log1.Source = "EvtLab2Source"; // Actual creation happens next log1.WriteEntry("Example message", EventLogEntryType.Information, 123, 1); } catch (Exception e) { Console.WriteLine(e.Message); } Console.WriteLine("Press ENTER to finish"); Console.ReadLine(); } } }
The recommended way, which does not seem to be covered on the Training Kit (so probably not on the exam) is to use the EventLogInstaller class during the installation of the application. For reference purposes seeMSDN
Exam objective:Manage system processes and monitor the performance of a .NET Framework application by using the diagnostics functionality of the .NET Framework 2.0.
(Refer System.Diagnostics namespace)
Get a list of all running processes.
Retrieve information about the current process -MSDN
Get a list of all modules loaded by a process
PerformanceCounter class, PerformanceCounterCategory, and CounterCreationData class
Start a process both by using and by not using command-line arguments
StackTrace class -MSDN
StackFrame class -MSDN
Exam objective:Debug and trace a .NET Framework application by using the System.Diagnostics namespace.
Debug class and Debugger class
Debug class example
using System; using System.Diagnostics; using System.IO; using System.Reflection; class Program { static void Main(string[] args) { Debug.WriteLine("This is (by default) printed in the Output window."); //remove default listener Debug.Listeners.RemoveAt(0); //add a listener that can write to the Console window Debug.Listeners.Add(new ConsoleTraceListener()); Debug.WriteLine("This is printed in the console window."); //add a default listener again Debug.Listeners.Add(new DefaultTraceListener()); Debug.WriteLine("This is printed in both the Output and the Console window."); //remove all listeners Debug.Listeners.Clear(); //add a listener that writes to a file Debug.Listeners.Add(new TextWriterTraceListener(File.Create("C:\\test.txt"))); Debug.WriteLine("This is only printed to the newly created file."); //here we need to flush the output buffer Debug.Flush(); //keep console window open in debug mode Console.ReadLine(); } }
Trace class -MSDN
CorrelationManager class -MSDN
TraceListener class -MSDN
TraceSource class -MSDN
TraceSwitch class -MSDN
XmlWriterTraceListener class -MSDN
DelimitedListTraceListener class -MSDN
EventlogTraceListener class -MSDN
Debugger attributes -MSDN
Exam objective:Embed management information and events into a .NET Framework application.
(Refer System.Management namespace -MSDN)
Retrieve a collection of Management objects by using the ManagementObjectSearcher class and its derived classes
WMI basic example
class Program { static void Main(string[] args) {//Print all management info in the WMI class Win32_ComputerSystem PrintManagementInfo("Win32_ComputerSystem");//wait for user input to keep console window up in debug mode Console.ReadLine(); } static void PrintManagementInfo(string WMIClassName) { ManagementObjectSearcher mos;//Get all managementobjects of the specified class mos = new ManagementObjectSearcher("SELECT * FROM " + WMIClassName); foreach (ManagementObject MOCollection in mos.Get()) { foreach (PropertyData p in MOCollection.Properties) {//Some properties are arrays, //in which case the code below only prints //the type of the array. //Add a check with IsArray() and a loop //to display the individual array values. Console.WriteLine("{0}: {1}", p.Name, p.Value); } } } }
ManagementObjectSearcher example
class Program { static void Main(string[] args) { // Console.WriteLine("Physical disks: "); PrintManagementInfoProperty("Win32_DiskDrive", "Name"); Console.WriteLine("*****************************"); // Console.WriteLine("Logical disks: "); PrintManagementInfoProperty("Win32_LogicalDisk", "Name"); Console.WriteLine("*****************************"); // Console.WriteLine("Network adapters: "); PrintManagementInfoProperty("Win32_NetworkAdapter", "Name"); Console.WriteLine("*****************************"); // Console.WriteLine("Processes: "); PrintManagementInfoProperty("Win32_Process", "Name"); Console.WriteLine("*****************************"); ////wait for user input to keep console window up in debug mode Console.ReadLine(); } static void PrintManagementInfoProperty(string WMIClassName, string WMIPropertyName) { ManagementObjectSearcher mos;//Get the specified property for all objects of the specified class mos = new ManagementObjectSearcher("SELECT " + WMIPropertyName + " FROM " + WMIClassName); foreach (ManagementObject mo in mos.Get()) { PropertyData p = mo.Properties[WMIPropertyName]; Console.WriteLine("{0}", p.Value); } } }
Enumarating services example
class Program { static void Main(string[] args) { Console.WriteLine("Running services: "); //form the query, providing a WMI class name and a condition SelectQuery query = new SelectQuery("Win32_Service", "State='Running'"); //find matching management objects ManagementObjectSearcher mos = new ManagementObjectSearcher(query); // foreach (ManagementObject mo in mos.Get()) { Console.WriteLine(mo.Properties["Name"].Value); } // //wait for user input to keep console window up in debug mode Console.ReadLine(); } }
ManagementQuery class -MSDN
EventQuery class -MSDN
Subscribe to management events by using the ManagementEventWatcher class -MSDN