EventLogInstaller EventLogInstaller EventLogInstaller EventLogInstaller Class

定义

使您能够安装和配置应用程序在运行时所读取或写入的事件日志。Allows you to install and configure an event log that your application reads from or writes to when running.

public ref class EventLogInstaller : System::Configuration::Install::ComponentInstaller
public class EventLogInstaller : System.Configuration.Install.ComponentInstaller
type EventLogInstaller = class
    inherit ComponentInstaller
Public Class EventLogInstaller
Inherits ComponentInstaller
继承

示例

下面的代码示例设置新事件源的安装属性。The following code example sets the installation properties for a new event source. 此代码示例设置源名称和事件日志名称, 并将添加EventLogInstaller Installers到集合中。The code example sets the source name and the event log name, and adds the EventLogInstaller to the Installers collection.

#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)]
ref class MyEventLogInstaller: public Installer
{
private:
   EventLogInstaller^ myEventLogInstaller;

public:
   MyEventLogInstaller()
   {
      // Create an instance of an EventLogInstaller.
      myEventLogInstaller = gcnew EventLogInstaller;

      // Set the source name of the event log.
      myEventLogInstaller->Source = "NewLogSource";
         
      // Set the event log that the source writes entries to.
      myEventLogInstaller->Log = "MyNewLog";
         
      // Add myEventLogInstaller to the Installer collection.
      Installers->Add( myEventLogInstaller );
   }
};
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 an EventLogInstaller.
        myEventLogInstaller = new EventLogInstaller();

        // Set the source name of the event log.
        myEventLogInstaller.Source = "NewLogSource";

        // Set the event log that the source writes entries to.
        myEventLogInstaller.Log = "MyNewLog";

        // Add myEventLogInstaller to the Installer collection.
        Installers.Add(myEventLogInstaller);   
    }

    public static void Main()
    {
        MyEventLogInstaller myInstaller = new MyEventLogInstaller();
    }
}
   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 an EventLogInstaller.
      myEventLogInstaller = New EventLogInstaller()

      ' Set the source name of the event log.
      myEventLogInstaller.Source = "NewLogSource"

      ' Set the event log that the source writes entries to.
      myEventLogInstaller.Log = "MyNewLog"

      ' Add myEventLogInstaller to the Installer collection.
      Installers.Add(myEventLogInstaller)
   End Sub

 Public Shared Sub Main()
 End Sub
 Dim myInstaller As New EventLogInstaller()
End Class

注解

安装事件日志时, 由installutil.exe (安装程序工具)使用。 EventLogInstallerThe EventLogInstaller is used by the Installutil.exe (Installer Tool) when installing an event log. EventLogInstaller类只能在本地计算机上安装事件日志。The EventLogInstaller class can install event logs only on the local computer.

当应用程序写入事件日志时使用类;不需要为应用程序使用事件日志安装程序来读取事件日志。EventLogInstallerUse the EventLogInstaller class when your application writes to an event log; it is not necessary to use an event log installer for your application to read from an event log. 应用程序和服务应写入应用程序日志或自定义日志。Applications and services should write to the Application log or a custom log. 设备驱动程序应该写入系统日志。Device drivers should write to the System log.

备注

安全日志为只读。The Security log is read-only.

安装程序将创建在Source属性中指定的事件源, 并将其注册到属性中Log指定的事件日志。The installer creates the event source that you specify in the Source property and registers it for the event log specified in Log property. 此行为类似于CreateEventSource EventLog在组件上调用。This behavior is similar to calling CreateEventSource on the EventLog component.

WriteEvent使用和WriteEntry方法可将事件写入事件日志。Use the WriteEvent and WriteEntry methods to write events to an event log. 您必须指定事件源以写入事件;在写入包含源的第一个条目之前, 必须创建并配置事件源。You must specify an event source to write events; you must create and configure the event source before writing the first entry with the source.

在应用程序安装过程中创建新的事件源。Create the new event source during the installation of your application. 这样, 操作系统就可以刷新其已注册事件源的列表及其配置。This allows time for the operating system to refresh its list of registered event sources and their configurations. 如果操作系统尚未刷新其事件源列表, 而你尝试使用新源写入事件, 则写入操作将失败。If the operating system has not refreshed its list of event sources, and you attempt to write an event with the new source, the write operation will fail. 您可以使用EventLogInstallerCreateEventSource方法来配置新源。You can configure a new source using an EventLogInstaller, or using the CreateEventSource method. 您必须对该计算机具有管理权限才能创建新的事件源。You must have administrative rights on the computer to create a new event source.

可以为现有事件日志或新的事件日志创建事件源。You can create an event source for an existing event log or a new event log. 为新的事件日志创建新源时, 系统将为该日志注册源, 但在向其中写入第一个条目之前, 不会创建日志。When you create a new source for a new event log, the system registers the source for that log, but the log is not created until the first entry is written to it.

若要安装事件日志, 请创建从Installer继承的项目安装程序类, 并将类trueRunInstallerAttribute设置为。To install an event log, create a project installer class that inherits from Installer, and set the RunInstallerAttribute for the class to true. 在项目中, EventLogInstaller为应用程序将写入的每个事件日志创建, 并将实例添加到项目安装程序类。Within your project, create an EventLogInstaller for each event log that your application will write to and add the instance to your project installer class.

调用installutil.exe (安装程序工具)时, 它将查看RunInstallerAttributeWhen the Installutil.exe (Installer Tool) is called, it looks at the RunInstallerAttribute. 如果是true, 则该工具将安装与项目安装程序Installers关联的集合中的所有项。If it is true, the tool installs all the items in the Installers collection that are associated with your project installer. 如果RunInstallerAttributefalse, 则该工具将忽略项目安装程序。If RunInstallerAttribute is false, the tool ignores the project installer.

在将实例添加EventLogInstaller Installers到项目安装程序的集合之前或之后, 但在安装程序工具运行之前修改的其他属性。You modify other properties of an EventLogInstaller either before or after adding the instance to the Installers collection of your project installer, but before the installer tool runs. 如果你的应用Source程序将写入事件日志, 则必须设置属性。You must set the Source property if your application will be writing to the event log.

用于为新的或现有的事件日志注册新源; 不要使用EventLogInstaller来更改现有源。 EventLogInstallerUse EventLogInstaller to register a new source for a new or existing event log; do not use EventLogInstaller to change an existing source. EventLogInstaller类不会修改现有源的配置属性以匹配指定的安装属性。The EventLogInstaller class does not modify the configuration properties of an existing source to match the specified installation properties. 如果InstallSource属性与为计算机上的不同事件日志注册的源名称匹配, 则该方法将引发异常。The Install method throws an exception if the Source property matches a source name that is registered for a different event log on the computer. 如果属性与已为Install Log属性中指定的相同事件日志注册的源名称匹配, 则该方法不会注册源。 SourceThe Install method does not register the source if the Source property matches a source name that is already registered for the same event log specified in the Log property.

可以向事件类别和消息字符串的本地化资源文件注册事件源。You can register the event source with localized resource files for your event category and message strings. 应用程序可以使用资源标识符而不是指定实际字符串来编写事件日志项。Your application can write event log entries using resource identifiers, rather than specifying the actual string. 事件查看器使用资源标识符从本地化的资源文件中查找并显示相应的字符串。The Event Viewer uses the resource identifier to find and display the corresponding string from the localized resource file based on current language settings. 您可以为事件类别、消息和参数插入字符串注册单独的文件, 也可以为所有这三种类型的字符串注册同一资源文件。You can register a separate file for event categories, messages, and parameter insertion strings, or you can register the same resource file for all three types of strings. CategoryCount使用、 CategoryResourceFileMessageResourceFile和属性将源配置为将本地化项写入事件日志。ParameterResourceFileUse the CategoryCount, CategoryResourceFile, MessageResourceFile, and ParameterResourceFile properties to configure the source to write localized entries to the event log. 如果你的应用程序将字符串值直接写入事件日志, 则无需设置这些属性。If your application writes strings values directly to the event log, you do not need to set these properties.

源必须配置为写入本地化项或写入直接字符串。The source must be configured either for writing localized entries or for writing direct strings. 如果应用程序使用资源标识符和字符串值写入条目, 则必须注册两个不同的源。If your application writes entries using both resource identifiers and string values, you must register two separate sources. 例如, 使用资源文件配置一个源, 然后在WriteEvent方法中使用该源, 将使用资源标识符的项写入事件日志。For example, configure one source with resource files, and then use that source in the WriteEvent method to write entries using resource identifiers to the event log. 创建不含资源文件的其他源, 然后在WriteEntry方法中使用该源, 使用该源直接向事件日志写入字符串。Create a different source without resource files and then use that source in the WriteEntry method to write strings directly to the event log using that source.

通常, 你不会从代码中调用EventLogInstaller类的方法; 它们通常仅由 installutil.exe 调用。Typically, you do not call the methods of the EventLogInstaller class from within your code; they are generally called only by Installutil.exe. 该工具会在安装Install过程中自动调用此方法。The tool automatically calls the Install method during the installation process. 如果需要, 它会通过调用Rollback生成异常的对象的方法来实现故障。It backs out failures, if necessary, by calling the Rollback method for the object that generated the exception.

构造函数

EventLogInstaller() EventLogInstaller() EventLogInstaller() EventLogInstaller()

初始化 EventLogInstaller 类的新实例。Initializes a new instance of the EventLogInstaller class.

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(Inherited from Component)
CategoryCount CategoryCount CategoryCount CategoryCount

获取或设置类别资源文件中类别的数目。Gets or sets the number of categories in the category resource file.

CategoryResourceFile CategoryResourceFile CategoryResourceFile CategoryResourceFile

获取或设置包含源的类别字符串的资源文件的路径。Gets or sets the path of the resource file that contains category strings for the source.

Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
Context Context Context Context

获取或设置关于当前安装的信息。Gets or sets information about the current installation.

(Inherited from Installer)
DesignMode DesignMode DesignMode DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
HelpText HelpText HelpText HelpText

获取安装程序集合中所有安装程序的帮助文字。Gets the help text for all the installers in the installer collection.

(Inherited from Installer)
Installers Installers Installers Installers

获取该安装程序包含的安装程序的集合。Gets the collection of installers that this installer contains.

(Inherited from Installer)
Log Log Log Log

获取或设置要向其设置源的日志的名称。Gets or sets the name of the log to set the source to.

MessageResourceFile MessageResourceFile MessageResourceFile MessageResourceFile

获取或设置资源文件的路径,该文件包含源的消息格式字符串。Gets or sets the path of the resource file that contains message formatting strings for the source.

ParameterResourceFile ParameterResourceFile ParameterResourceFile ParameterResourceFile

获取或设置资源文件的路径,该文件包含源的消息参数字符串。Gets or sets the path of the resource file that contains message parameter strings for the source.

Parent Parent Parent Parent

获取或设置包含该安装程序所属的集合的安装程序。Gets or sets the installer containing the collection that this installer belongs to.

(Inherited from Installer)
Site Site Site Site

获取或设置 ComponentISiteGets or sets the ISite of the Component.

(Inherited from Component)
Source Source Source Source

获取或设置要在日志中注册的源名称。Gets or sets the source name to register with the log.

UninstallAction UninstallAction UninstallAction UninstallAction

获取或设置一个值,以指示 Installutil.exe(安装程序工具)在卸载时应删除事件日志还是保留其安装状态。Gets or sets a value that indicates whether the Installutil.exe (Installer Tool) should remove the event log or leave it in its installed state at uninstall time.

方法

Commit(IDictionary) Commit(IDictionary) Commit(IDictionary) Commit(IDictionary)

在派生类中重写时,完成安装事务。When overridden in a derived class, completes the install transaction.

(Inherited from Installer)
CopyFromComponent(IComponent) CopyFromComponent(IComponent) CopyFromComponent(IComponent) CopyFromComponent(IComponent)

复制安装时所需要的 EventLog 组件(与事件日志对应)的属性值。Copies the property values of an EventLog component that are required at installation time for an event log.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(Inherited from MarshalByRefObject)
Dispose() Dispose() Dispose() Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

获取当前实例的 TypeGets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Install(IDictionary) Install(IDictionary) Install(IDictionary) Install(IDictionary)

执行安装并将事件日志信息写入注册表。Performs the installation and writes event log information to the registry.

IsEquivalentInstaller(ComponentInstaller) IsEquivalentInstaller(ComponentInstaller) IsEquivalentInstaller(ComponentInstaller) IsEquivalentInstaller(ComponentInstaller)

确定安装程序和指定的另一个安装程序是否引用同一个源。Determines whether an installer and another specified installer refer to the same source.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnAfterInstall(IDictionary) OnAfterInstall(IDictionary) OnAfterInstall(IDictionary) OnAfterInstall(IDictionary)

引发 AfterInstall 事件。Raises the AfterInstall event.

(Inherited from Installer)
OnAfterRollback(IDictionary) OnAfterRollback(IDictionary) OnAfterRollback(IDictionary) OnAfterRollback(IDictionary)

引发 AfterRollback 事件。Raises the AfterRollback event.

(Inherited from Installer)
OnAfterUninstall(IDictionary) OnAfterUninstall(IDictionary) OnAfterUninstall(IDictionary) OnAfterUninstall(IDictionary)

引发 AfterUninstall 事件。Raises the AfterUninstall event.

(Inherited from Installer)
OnBeforeInstall(IDictionary) OnBeforeInstall(IDictionary) OnBeforeInstall(IDictionary) OnBeforeInstall(IDictionary)

引发 BeforeInstall 事件。Raises the BeforeInstall event.

(Inherited from Installer)
OnBeforeRollback(IDictionary) OnBeforeRollback(IDictionary) OnBeforeRollback(IDictionary) OnBeforeRollback(IDictionary)

引发 BeforeRollback 事件。Raises the BeforeRollback event.

(Inherited from Installer)
OnBeforeUninstall(IDictionary) OnBeforeUninstall(IDictionary) OnBeforeUninstall(IDictionary) OnBeforeUninstall(IDictionary)

引发 BeforeUninstall 事件。Raises the BeforeUninstall event.

(Inherited from Installer)
OnCommitted(IDictionary) OnCommitted(IDictionary) OnCommitted(IDictionary) OnCommitted(IDictionary)

引发 Committed 事件。Raises the Committed event.

(Inherited from Installer)
OnCommitting(IDictionary) OnCommitting(IDictionary) OnCommitting(IDictionary) OnCommitting(IDictionary)

引发 Committing 事件。Raises the Committing event.

(Inherited from Installer)
Rollback(IDictionary) Rollback(IDictionary) Rollback(IDictionary) Rollback(IDictionary)

通过回滚安装过程写入注册表的事件日志信息,将计算机还原为安装前的状态。Restores the computer to the state it was in before the installation by rolling back the event log information that the installation procedure wrote to the registry.

ToString() ToString() ToString() ToString()

返回包含 Component 的名称的 String(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(Inherited from Component)
Uninstall(IDictionary) Uninstall(IDictionary) Uninstall(IDictionary) Uninstall(IDictionary)

通过从注册表中移除事件日志信息来移除安装。Removes an installation by removing event log information from the registry.

事件

AfterInstall AfterInstall AfterInstall AfterInstall

Install(IDictionary) 属性中的所有安装程序的 Installers 方法都运行后发生。Occurs after the Install(IDictionary) methods of all the installers in the Installers property have run.

(Inherited from Installer)
AfterRollback AfterRollback AfterRollback AfterRollback

在回滚 Installers 属性中所有安装程序的安装后发生。Occurs after the installations of all the installers in the Installers property are rolled back.

(Inherited from Installer)
AfterUninstall AfterUninstall AfterUninstall AfterUninstall

Installers 属性中所有安装程序都执行它们的卸载操作后发生。Occurs after all the installers in the Installers property perform their uninstallation operations.

(Inherited from Installer)
BeforeInstall BeforeInstall BeforeInstall BeforeInstall

在安装程序集合中每个安装程序的 Install(IDictionary) 方法运行前发生。Occurs before the Install(IDictionary) method of each installer in the installer collection has run.

(Inherited from Installer)
BeforeRollback BeforeRollback BeforeRollback BeforeRollback

在回滚 Installers 属性中的安装程序前发生。Occurs before the installers in the Installers property are rolled back.

(Inherited from Installer)
BeforeUninstall BeforeUninstall BeforeUninstall BeforeUninstall

Installers 属性中的安装程序执行它们的卸载操作前发生。Occurs before the installers in the Installers property perform their uninstall operations.

(Inherited from Installer)
Committed Committed Committed Committed

Installers 属性中的所有安装程序均提交它们的安装后发生。Occurs after all the installers in the Installers property have committed their installations.

(Inherited from Installer)
Committing Committing Committing Committing

Installers 属性中的安装程序提交它们的安装前发生。Occurs before the installers in the Installers property commit their installations.

(Inherited from Installer)
Disposed Disposed Disposed Disposed

当通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

适用于

另请参阅