Share via


How to: Create EventLog Component Instances 

You create EventLog components when you want to add event log functionality to your application. EventLog components allow you to connect to existing event logs, write entries to them, and react to entries the logs receive.

EventLog components have no visual user interface. If you add an instance of the EventLog component to a visual item (such as a form), the component appears in a small area below the bottom border of the form. This is known as the component tray and acts as a place to display all of the non-visual items associated with the form.

NoteNote

Non-visual classes that inherit from Component support a visual design surface similar to the component tray, on which your EventLog component and other components are arranged. The arrangement of items on this designer is not important, as the interface you see will never be displayed to the application's end users.

There are several ways you can create an instance of the EventLog component:

  • You can drag an instance of the EventLog component from the Components tab of the Toolbox to a form or other designer.

  • You can locate the log you want in Server Explorer and add it to your designer, creating an instance of the EventLog component that is pre-configured to point to that log.

  • You can create an instance of the EventLog component in code.

NoteNote

The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings.

To create an EventLog component instance from Server Explorer

  1. Open Server Explorer. For more information, see How to: Access and Initialize Server Explorer/Database Explorer.

  2. Expand the node for the server you want to view, and then locate and expand the Event Logs node beneath it.

  3. Locate the log you want to add to your project, and then right-click it.

  4. Click Add to Designer.

  5. Set the necessary properties for the component. For more information, see How to: Configure EventLog Component Instances.

To create an EventLog component instance from the Toolbox

  1. Access the Components tab of the Toolbox.

  2. Select the EventLog icon and drag it to the designer surface for your form or component.

  3. Set the necessary properties for the component. For more information, see How to: Configure EventLog Component Instances.

To create an EventLog component instance programmatically

  1. Create an instance of the EventLog class in code. Your code might look like this:

    Dim EventLog1 As New System.Diagnostics.EventLog()
    
    System.Diagnostics.EventLog EventLog1 = new System.Diagnostics.EventLog();
    
    System.Diagnostics.EventLog EventLog1 =  new System.Diagnostics.EventLog();
    
  2. Set the necessary properties for the component. For more information, see How to: Configure EventLog Component Instances.

See Also

Tasks

How to: Configure EventLog Component Instances
How to: Add Your Application as a Source of Event Log Entries
How to: Determine If an Event Source Exists
How to: Remove an Event Source
Walkthrough: Exploring Event Logs, Event Sources, and Entries

Concepts

Introduction to the EventLog Component