Adding Application Code

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.

The Logging Application Block is designed to support the most common scenarios for logging information. When adding your application code, refer to the scenarios in the Key Scenarios sections and select the ones that best suit your situation. Use the code that accompanies the scenario either as is, or adapt it as necessary.

First, prepare your application to use the Logging Application Block. The following procedure describes how to include the necessary Enterprise Library assemblies and elements in your code.

To prepare your application

  1. Set a reference to the Logging Application Block assembly:

    If you are using C#, in Visual Studio, right-click References in Solution Explorer, and then click Add References to add references to the Microsoft.Practices.EnterpriseLibrary.Logging.dll assembly, Microsoft.Practices.EnterpriseLibrary.Common.dll assembly, and Microsoft.Practices.EnterpriseLibrary.ObjectBuilder.dll assembly.

    If you are using Visual Basic, in Visual Studio, double-click My Project, click the References tab, and then click Add Reference to select the assembly. In the list of imported namespaces at the bottom of the tab, select the following check boxes: Microsoft.Practices.EnterpriseLibrary.Logging, Microsoft.Practices.EnterpriseLibrary.Common.dll, and Microsoft.Practices.EnterpriseLibrary.ObjectBuilder.dll.

  2. (Optional) To use elements from the Logging Application Block without fully qualifying the element reference, you can add the following using statements (C#) or Imports statements (Visual Basic) to the top of your source code file.

    using Microsoft.Practices.EnterpriseLibrary.Logging;
    using Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation;
    using Microsoft.Practices.EnterpriseLibrary.Logging.Filters;
    
    'Usage
    Imports Microsoft.Practices.EnterpriseLibrary.Logging
    Imports Microsoft.Practices.EnterpriseLibrary.Logging.ExtraInformation
    Imports Microsoft.Practices.EnterpriseLibrary.Logging.Filters
    

    Note

    For Visual Basic projects, you can also use the References page of the Project Designer to manage references and imported namespaces. To access the References page, select a project node in Solution Explorer, and then click Properties on the Project menu. When the Project Designer appears, click the References tab.

    The ExtraInformation providers gather context information that is useful but not always necessary because it is expensive to collect. Examples are stack track information and COM+ information. The ExtraInformation providers add the information to a dictionary. You can choose which providers to use (if any), and add the resulting dictionary to the LogEntry.ExtendedProperties property.

    Filters are optional. You only need to import the Microsoft.Practices.EnterpriseLibrary.Logging.Filters namespace if you are going to refer to specific filters in your application code.

  3. If you are using the FormatterDatabaseTraceListener class, add a reference to the Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll. If you use the FormatterDatabaseTraceListener class, you must prepare the application to use the Data Access Application Block. For more details, see the documentation for that application block.

  4. Add the application code.

Each key scenario demonstrates how to incorporate these steps into an 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.