Configuring the Application Blocks

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.

Configuration information for the Enterprise Library application blocks is stored in XML format. Typically, the information exists in an XML file. By default, the XML file that contains the information is the application configuration file.

You can manually edit the XML data, but the Enterprise Library provides two configuration tools that greatly simplify this task. These tools are the stand-alone Configuration Console and the Configuration Editor that is integrated with Visual Studio. If you choose to manually edit the XML, refer to the appropriate application block documentation for schema details.

The following examples use the Configuration Console to demonstrate how to configure an application block. The procedures are the same for the Configuration Editor. The only significant difference between the two is how configuration files are opened in each tool. For more information about this topic, see Using the Configuration Editor.

Using the Configuration Tools

The Enterprise Library configuration tools are graphical tools that allow you to create, change, and validate application block settings without having to manually edit the XML configuration files where they are stored. There are two tools to choose from: the Configuration Editor, which is integrated with Visual Studio 2005, and the configuration console, which is a stand-alone tool. These tools display the available configuration settings, the default values that you can change, and information about what each setting means.

To use the Configuration Editor

  1. Open a solution in Visual Studio 2005.
  2. In Solution Explorer, right-click the configuration file, and then click Edit Enterprise Library Configuration.
  3. Right-click Application Configuration Node, point to New, and then click an application block from the list. For example, click Logging Application Block.
  4. The configuration options for that application block display, along with their default values. Right-click and change the configuration options that you want to change. For example, if you are configuring the Logging Application Block and you want to add a flat file trace listener, do the following:
    1. Right-click Trace Listeners, point to New, and then click FlatFile TraceListener.
    2. In the Properties pane next to the FileName property, click the ellipsis button (...), and then enter the file name and location of the trace listener file.
  5. After you make all your configuration changes, click Save on the File menu.

In Visual Studio, the XML Editor is the default editor for .config files. When you double-click a .config file in Solution Explorer, the XML Editor opens. The following procedure describes how to change the default editor.

To set Configuration Editor as the default editor

  1. Open a project in Visual Studio.
  2. In Solution Explorer, right-click a configuration (.config) file.
  3. Click Open.
  4. Click Enterprise Library Configuration Editor.
  5. Click the Set as Default button.
  6. Click OK.

To use the configuration console

  1. On the taskbar, click Start, point to All Programs, point to Microsoft patterns & practices, point to Enterprise Library 3.1 – May 2007, and then click Enterprise Library Configuration. This loads the copy of the Configuration Console that uses the strong-named assemblies. If you are using a different set of assemblies, navigate to the appropriate copy of EntLibConfig.exe using Windows Explorer.

  2. On the File menu, click New Application (if you are configuring a new application) or Open Application (if you are configuring an existing application).

    Note

    When you open an existing application configuration file, the Configuration Console displays the Data Access Application Block if your Machine.config file contains any connection strings. For more information, see Usage Notes.

  3. Right-click Application Configuration Node, point to New, and then click an application block from the list. For example, click the Logging Application Block.

  4. The configuration options for that application block display, along with their default values. Right-click and change the configuration options that you want to change. For example, if you are configuring the Logging Application Block and you want to add a flat file trace listener, do the following:

    1. Right-click Trace Listeners, point to New, and then click FlatFile TraceListener.
    2. In the Properties pane next to the FileName property, click the ellipsis button (...), and then enter the file name and location of the trace listener file.
  5. After you make all your configuration changes, click Save Application on the File menu.

The documentation for each application block contains procedures for configuring it.

Usage Notes

Here are some additional points about the Configuration Console:

  • The Configuration Console does not support editing or storing Enterprise Library configuration sections in the Machine.config file. Enterprise Library configuration section information in the Machine.config file can be accessed at run time, but it cannot be modified at design time. Therefore, you should not store Enterprise Library configuration information in the Machine.config file.
  • The Configuration Console displays connection strings stored in the Machine.config file, but it only saves connection strings to the application configuration file. If you use the Configuration Console to modify connection strings stored in the Machine.config file, the changes will be lost.
  • At run time, the Data Access Application Block can use connection strings that are defined in the Machine.config file.
  • The Configuration Console displays connection string information under the Data Access Application Block configuration information. This means that if there are connection strings defined in the Machine.config file, you will see the Data Access Application Block node when you open any application configuration file, regardless of whether you added the application block to your configuration file.
  • If your application configuration includes a custom provider, you must make the custom provider assembly available to the configuration console. To do this, you can copy the assembly to the same directory as the Configuration Console executable or install it in the global assembly cache. You can also use the DEVPATH environment variable to allow the Configuration Console to locate the custom provider assembly.
  • The <appSettings> sections must be included in a single file and not distributed across multiple files. Examples of files that you cannot edit include the Machine.config file and <appSettings> sections that include the optional file attribute that specifies a relative path to an external configuration file.

Using Alternate Configuration Sources

You can use other sources—such as a SQL database—to derive your configuration information. The application configuration file contains a configuration section that defines the configuration source. If this section is missing, the application configuration file is used as the configuration source. However, even if you use an alternate source, the Enterprise Library saves your configuration information as XML. The core configuration classes that support reading configuration information first try to read the requested configuration section from the configured source location. If the configuration section is not found, the core classes try to read the configuration section from the System Configuration Source.

To use an alternate configuration source

  1. Start the Enterprise Library Configuration Console. To use the Configuration Console, click Start, point to AllPrograms, point to Microsoftpatterns&practices, point to Enterprise Library 3.1 – May 2007, and then click Enterprise LibraryConfiguration.
  2. On the File menu, click New Application (if you are configuring a new application) or Open Application (if you are configuring an existing application).
  3. Right-click Application Configuration Node, point to New, and then click Configuration Sources.
  4. Right-click Configuration Sources, point to New, and then click the type of Configuration Source you want to use (such as File Configuration Source).
  5. Use the Properties pane to enter the desired configuration properties for the new configuration source.
  6. Select the Configuration Sources node, and then select the SelectedSource property in the Properties pane.
  7. Click the arrow adjacent to System Configuration Source, and then click the configuration source you want to use.
  8. After you make your configuration changes, click File, and then click Save Application.
Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

The latest Enterprise Library information can be found at the Enterprise Library site.