Export (0) Print
Expand All

EventLogInstaller Class

Allows you to install and configure an event log that your application reads from or writes to when running. This class is called by the installation utility, for example, InstallUtil.exe, when installing an event log.

For a list of all members of this type, see EventLogInstaller Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Configuration.Install.Installer
            System.Configuration.Install.ComponentInstaller
               System.Diagnostics.EventLogInstaller

[Visual Basic]
Public Class EventLogInstaller
   Inherits ComponentInstaller
[C#]
public class EventLogInstaller : ComponentInstaller
[C++]
public __gc class EventLogInstaller : public ComponentInstaller
[JScript]
public class EventLogInstaller extends ComponentInstaller

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The EventLogInstaller is used by the installation utility to write registry values that are associated with the event log. For more information on installation utilities, see Installer Tool (Installutil.exe). The EventLogInstaller class can install event logs only on the local computer.

The installer creates the event source you specify in the Source property. This behavior is very similar to calling CreateEventSource on the EventLog component. Because event sources are necessary only when writing to an event log, it is not necessary to use an event log installer when you will be only reading but not writing to a log.

To install an event log, create a project installer class that inherits from Installer, and set the RunInstallerAttribute for the class to true. Within your project, create an EventLogInstaller instance for each event log your application will write to and add the instance to your project installer class.

When the install utility is called, it looks at the RunInstallerAttribute. If it is true, the utility installs all the items in the Installers collection associated with your project installer. If RunInstallerAttribute is false, the utility ignores the project installer.

You modify other properties of an EventLogInstaller instance either before or after adding the instance to the Installers collection of your project installer, but before the installer utility runs. You must set the Source property if your application will be writing to the event log.

If you set the Source property, but the specified source already exists, EventLogInstaller deletes the previous source and recreates it, assigning the source to the log you specify in the Log property.

Typically, you do not call the methods of the EventLogInstaller class from within your code; they are generally called only by the InstallUtil.exe installation utility. The utility automatically calls the Install method during the installation process. It backs out failures, if necessary, by calling the Rollback method for the object that generated the exception.

Example

[Visual Basic] 
Imports System
Imports System.Configuration.Install
Imports System.Diagnostics
Imports System.ComponentModel

<RunInstaller(True)>  _
Public Class MyEventLogInstaller
   Inherits Installer
   Private myEventLogInstaller As EventLogInstaller
   
   Public Sub New()
      ' Create an instance of 'EventLogInstaller'.
      myEventLogInstaller = New EventLogInstaller()
      ' Set the 'Source' of the event log, to be created.
      myEventLogInstaller.Source = "MyNewLog"
      ' Set the 'Log' that the source is created in.
      myEventLogInstaller.Log = "MyNewLog"
      ' Add myEventLogInstaller to 'InstallerCollection'.
      Installers.Add(myEventLogInstaller)
   End Sub 'New
   Public Shared Sub Main()
   End Sub 'Main
End Class 'MyEventLogInstaller

[C#] 
using System;
using System.Configuration.Install;
using System.Diagnostics;
using System.ComponentModel;

[RunInstaller(true)]
public class MyEventLogInstaller: Installer
{
   private EventLogInstaller myEventLogInstaller;
   public MyEventLogInstaller() 
   {
      // Create an instance of 'EventLogInstaller'.
      myEventLogInstaller = new EventLogInstaller();
      // Set the 'Source' of the event log, to be created.
      myEventLogInstaller.Source = "MyNewLog";
      // Set the 'Log' that the source is created in.
      myEventLogInstaller.Log = "MyNewLog";
      // Add myEventLogInstaller to 'InstallerCollection'.
      Installers.Add(myEventLogInstaller);   
   }
   public static void Main()
   {
   }
}

[C++] 
#using <mscorlib.dll>
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Configuration::Install;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

[RunInstaller(true)]
__gc class MyEventLogInstaller : public Installer {
private:
    EventLogInstaller* myEventLogInstaller;

public:
    MyEventLogInstaller() {
        // Create an instance of 'EventLogInstaller'.
        myEventLogInstaller = new EventLogInstaller();
        // Set the 'Source' of the event log, to be created.
        myEventLogInstaller->Source = S"MyNewLog";
        // Set the 'Log' that the source is created in.
        myEventLogInstaller->Log = S"MyNewLog";
        // Add myEventLogInstaller to 'InstallerCollection'.
        Installers->Add(myEventLogInstaller);
    }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Diagnostics

Platforms: Windows NT Server 4.0, Windows NT Workstation 4.0, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: System.Configuration.Install (in System.Configuration.Install.dll)

See Also

EventLogInstaller Members | System.Diagnostics Namespace | EventLog | Installer Tool (Installutil.exe) | EventLog.CreateEventSource

Show:
© 2014 Microsoft