Export (0) Print
Expand All

Creating 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.

Note   Non-visual classes that inherit from System.ComponentModel.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.

To create an EventLog component instance from Server Explorer

  1. Open Server Explorer. For more information, see Accessing and Initializing Server Explorer.
  2. Expand the node for the server you want to view, and then locate and expand the Event Logs node beneath it.
    Note   The Servers node of Server Explorer is not available in the Standard Edition of Visual Basic and Visual C# .NET. For more information, see Visual Basic Standard Edition Features or Visual C# Standard Edition Features.
  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 Configuring 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 Configuring 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:
    ' Visual Basic
    Dim EventLog1 As New System.Diagnostics.EventLog()
    
    // C#
    System.Diagnostics.EventLog EventLog1 = new System.Diagnostics.EventLog();
    
  2. Set the necessary properties for the component. For more information, see Configuring EventLog Component Instances.

See Also

Introduction to the EventLog Component | Configuring EventLog Component Instances | Adding Your Application as a Source of Event Log Entries | Determining If an Event Source Exists | Removing an Event Source | Walkthrough: Exploring Event Logs, Event Sources, and Entries

Show:
© 2014 Microsoft