2.5 [Enterprise Library] configure application blocks

Source: Internet
Author: User
Tags configuration settings
Copyright (c) 2007 Dorian Deng. Signature Sharing is not commercially available.
Reprinted please indicate the source: http://blog.csdn.net/doriandeng/archive/2007/09/23/1797675.aspx

 

Used for Enterprise Library applicationsProgramThe configuration information of a block is saved in XML format. Generally, the information is stored in an XML file. The XML file contains the application configuration file.

You can manually modify XML data, but the Enterprise Library provides two configuration tools, greatly simplifying this task. These tasks are independent configuration console and the configuration editor integrated into Visual Studio. If you select to manually edit the XML file, see the corresponding application block documentation for more detailed information.

The following example uses the configuration console as an example to describe how to configure an application block. This process also applies to the configuration editor. The only difference between the two is how to open the configuration file in each tool. For more information about this topic, see use the configuration editor.

Use configuration tools

The Enterprise Library Configuration tool is a graphical tool that allows you to create, modify, and verify application block settings without manually modifying the xml configuration files they save. There are two tools to choose from: configuration Editor, which is integrated with Visual Studio 2005; configuration console, which is an independent tool. These tools display available configuration settings. You can modify the default values and the information that each setting means.

Use the configuration Editor
    1. Open a solution in Visual Studio 2005.

    2. In the solution browser, right-click the configuration file and selectEdit Enterprise Library Configuration.

    3. Right-click the application configuration node and pointNewAnd then click an application block from the list. For example, clickLogging Application Block.

    4. The options of the application and their default values are displayed. Right-click and modify the configuration options. For example, if you configure a log application block and add a flat file tracing listener, you can do the following:

      1. Right-clickTrace listeners, PointingNewAnd then clickFlatfile tracelistener.

      2. In the properties panelFilenameClick the ellipsis (...) button next to the property, and then enter the file name and track the location of the listening file.

    5. After modifying all the configurations, clickFileIn the menuSave.

In Visual Studio, the XML editor is the default editor of The. config file. When you double-click a. config file in the solution browser, the XML editor opens. The following process describes how to change the default editor.

Set the configuration editor as the default editor
    1. Open a file in Visual Studio.

    2. In the solution browser, right-click the configuration (. config) file.

    3. ClickOpen.

    4. ClickEnterprise Library configuration Editor.

    5. ClickSet as defaultButton.

    6. ClickOK.

Use the configuration Console
  1. In the taskbar, clickStart, PointingProgram, PointingMicrosoft patterns & Practices, PointingEnterprise Library 3.1-May 2007And then clickEnterprise Library Configuration. In this way, the configuration console that uses a strongly-named Assembly copy is loaded. If you want to use different Assembly sets, use the windows browser to navigate to the appropriate entlibconfig.exe copy.

  2. InFileIn the menu, clickNew Application(If you configure a new application), orOpen Application(If an existing application is configured ).

    Note:

    If you open an existing application configuration file, ifMachine. configContains any connection string. The configuration console displays the Data Access Application Block. For more information, see usage tips.

  3. Right-clickApplication configuration Node, PointingNewClick an application block from the list. For example, clickLogging Application Block.

  4. The options of the application and their default values are displayed. Right-click and modify the configuration options. For example, if you configure a log application block and add a flat file tracing listener, you can do the following:

    1. Right-clickTrace listeners, PointingNewAnd then clickFlatfile tracelistener.

    2. In the properties panelFilenameClick the ellipsis (...) button next to the property, and then enter the file name and track the location of the listening file.

  5. After modifying all the configurations, clickFileIn the menuSave Application.

Each application document contains the process of configuring it.

Usage tips

Some usage tips about the configuration console:

    • the Console does not support editing and saving the Enterprise Library configuration section in the machine. config file. The Enterprise Library configuration section information in the machine. config file can be accessed at runtime, but cannot be modified at design time. Therefore, the Enterprise Library configuration information cannot be saved to the machine. config file.

    • the configuration console displays the connection string saved in the machine. config file, but it only saves the connection string in the application configuration file. If you use the configuration console to modify the connection string stored in the machine. config file, the modification will be ignored.

    • at runtime, the Data Access Application Block can use the connection string saved in the machine. config file.

    • the configuration console displays the connection string information under the Data Access application block configuration information. This means that in the machine. if the connection string is defined in the config file, you will see Data Access to the Application Block node when opening any application configuration file, whether or not you have added the application block to the application configuration file.

    • If the application configuration contains a custom provider, you must create a custom provider Assembly available for the configuration console. To do this, you can copy the assembly to the configuration console executable file directory or install it to the Global Assembly Cache. You can also use the devpath environment variable to enable the configuration console to locate the custom provided assembly.

    • must be saved in a single file, but cannot be separated into multiple files. The file example is, and cannot be modified and saved on the machine. section in the config file, specifies the file attributes, which specify the path to the external file.

Use the available configuration Source

You can use other sources, such as SQL databases, to obtain configuration information. The application configuration file contains the configuration section of the configuration source. If this section is not found, the application configuration file will be used as the configuration source. However, if an optional configuration source is used, the Enterprise Library saves the configuration information as XML. The core configuration class supports reading configuration information. First, read the required configuration section from the configuration source location. If the configuration section is not found, the core class tries to read the configuration section from the System Configuration source.

Use an optional configuration Source
  1. Start the Enterprise Library configuration console. To use the configuration console, clickStart, PointingProgram, PointingMicrosoftpatterns & Practices, PointingEnterprise Library 3.1-May 2007And then clickEnterprise libraryconfiguration.

  2. InFileIn the menu, clickNew Application(If you configure a new application) orOpen Application(If you configure an existing application ).

  3. Right-click the application configuration node and pointNewAnd then clickConfiguration sources.

  4. Right-click Configuration source and pointNew, And then click the configuration source type to use (suchFile configuration Source).

  5. Use the properties panel to enter the desired configuration properties for the new configuration source.

  6. Select the configuration source node, and then selectSelectedsourceAttribute.

  7. ClickSystem Configuration SourceClick the arrow next to the configuration source to use.

  8. After modifying the configuration, clickFileAnd then clickSave Application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.