# .NET Development Foundation/Configuration
## Configuration, diagnostic, management, and installation

Exam objective: Embedding configuration, diagnostic, management, and installation features into a .NET Framework application

### Topics
#### Configuration management

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.

#### Event log

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 see MSDN
For specifics on the EventLog class and some cautions about its use see MSDN

#### Management information and events

Windows Management Instrumentation - MSDN

### Classes, Interfaces, and tools
#### Embed configuration management

Exam objective: Embed configuration management functionality into a .NET Framework application.
(Refer System.Configuration namespace)
Configuration class and ConfigurationManager class
    Configuration class - MSDN
    ConfigurationManager class - MSDN
ConfigurationSettings class, ConfigurationElement class, ConfigurationElementCollection class, and ConfigurationElementProperty class
    ConfigurationSettings class - MSDN
    ConfigurationElement class - MSDN
    ConfigurationElementCollection class - MSDN
    ConfigurationElementProperty class - MSDN
Implement IConfigurationSectionHandler interface - MSDN
ConfigurationSection class, ConfigurationSectionCollection class, ConfigurationSectionGroup class, and ConfigurationSectionGroupCollection class
    ConfigurationSection class - MSDN
    ConfigurationSectionCollection class - MSDN
    ConfigurationSectionGroup class - MSDN
    ConfigurationSectionGroupCollection - MSDN
Implement ISettingsProviderService interface - MSDN
Implement IApplicationSettingsProvider interface - MSDN
ConfigurationValidationBase class - MSDN
    No direct result on MSDN - to be checked
Implement IConfigurationSystem interface - MSDN

#### Create custom installer and configure application

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).
    For a "cookbook" on for the procedures discussed in this section see MSDN and the corresponding How-To section.
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 and MSDN
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

#### Manage an event log

Exam objective: Manage an event log by using the System.Diagnostics namespace
EventLog class - MSDN
EventSourceCreationData class - MSDN

##### Write to an event log

MSDN

##### Read from an event log

MSDN

##### Create a new event log

You create an EventLog by creating the first event source that writes to that log.
The two simplest way to do this are:
* Use the EventLog.CreateEventSource method
* Create an EventLog instance, specify a source and then write to the log. The actual creation takes place on execution of the first write.
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
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 see MSDN

#### Manage processes and monitor performance

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.
    Process class - MSDN
    For example code for GetCurrentProcess, GetProcessesByName, GetProcesses, and GetProcessById see MSDN
Retrieve information about the current process - MSDN
Get a list of all modules loaded by a process
    The Process.Modules property returns a strongly-typed collection of ProcessModule objects that represent the Process' currently loaded modules.
    For the Process.Modules property see MSDN
    For the ProcessModule class see MSDN
PerformanceCounter class, PerformanceCounterCategory, and CounterCreationData class
    PerformanceCounter class - MSDN
    PerformanceCounterCategory - MSDN
    CounterCreationData class - MSDN
Start a process both by using and by not using command-line arguments
    Starting a Process Overview
       Processes are started using one of the overloaded Process.Start methods. When passing sensitive data such as passwords to Process.Start, use one of the two overloaded Start methods that accept a SecureString as an argument type.
    External links
      * MSDN2 Entry for Starting a Process - Process.Start
      * MSDN2 Entry for Starting a Process with ProcessStartInfo. This example demonstrates how to launch IE.
      * MSDN2 Entry for Starting a Process with Command Line Arguments
      * MSDN2 Passing a Password as a SecureString to Process.Start
      * MSDN2 SecureString class
StackTrace class - MSDN
StackFrame class - MSDN

#### Debug and Trace

Exam objective: Debug and trace a .NET Framework application by using the System.Diagnostics namespace.
Debug class and Debugger class
    Debug class - MSDN
       The four static writing methods of the Debug class - Write, WriteLine, WriteIf and WriteLineIf - let you write debug messages to inspect your program's flow and catch errors. Calls to these methods are ignored in the release version of your program (see 'The ConditionalAttribute attribute' below for details).
       In Visual Studio, the default target for Debug's write methods is the Output window. You can use Debug's Listeners property to access the associated TraceListenerCollection. The following code shows how to use the Remove and Add methods of the collection to control where debug messages are sent to. If you add more than one listener of the same type, the associated target receives the text multiple times.
Debug class example
    Debugger class - MSDN
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
    DebuggerBrowsableAttribute class - MSDN
    DebuggerDisplayAttribute class - MSDN
    DebuggerHiddenAttribute class - MSDN
    DebuggerNonUserCodeAttribute class - MSDN
    DebuggerStepperBoundaryAttribute class - MSDN
    DebuggerStepThroughAttribute class - MSDN
    DebuggerTypeProxyAttribute class - MSDN
    DebuggerVisualizerAttribute class - MSDN

#### Embed management information

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
       The classes in the System.Management namespace let you use Windows Management Instrumentation (WMI) to manage computer systems. The most notable class in this namespace is ManagementObjectSearcher, that you can use to retrieve management objects based on a WMI query.
       Information that can be retrieved this way ranges from computer case type (notebook, desktop...) over processor and hard disks details to information about running services and processes. Consult the WMI Reference on MSDN for an overview of all WMI classes and their properties.
       In the example below a rough and dirty method is defined that prints all properties for all management information objects of a given WMI class. It is then used to print information about the current computer system.
WMI basic example
    ManagementObjectSearcher class - MSDN
    Enumerate all disk drivers, network adapters, and processes on a computer
       The following code uses one overload of the ManagementObjectSearcher constructor to list all physical and logical disk drives, network adapters and running processes on a system.
ManagementObjectSearcher example
    Retrieve information about all network connections
       Example to be provided
    Retrieve information about all services that are paused
       The following code uses a ManagementObjectSearcher object to retrieve all running services and then displays their names.
Enumarating services example
ManagementQuery class - MSDN
EventQuery class - MSDN
    ObjectQuery class - MSDN
Subscribe to management events by using the ManagementEventWatcher class - MSDN
Previous / Next