EventLogInstaller 类

定义

使您能够安装和配置应用程序在运行时所读取或写入的事件日志。

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
继承

示例

下面的代码示例设置新事件源的安装属性。 该代码示例设置源名称和事件日志名称,并将 添加到 EventLogInstaller 集合。Installers

#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

注解

EventLogInstaller安装事件日志时,Installutil.exe (安装程序工具) 使用 。 类 EventLogInstaller 只能在本地计算机上安装事件日志。

当应用程序写入事件日志时, EventLogInstaller 请使用 类;应用程序无需使用事件日志安装程序来读取事件日志。 应用程序和服务应写入应用程序日志或自定义日志。 设备驱动程序应写入系统日志。

注意

安全日志是只读的。

安装程序将创建在 属性中指定的 Source 事件源,并将其注册为 属性中指定的 Log 事件日志。 此行为类似于对EventLog组件调用 CreateEventSource

WriteEvent使用 和 WriteEntry 方法将事件写入事件日志。 必须指定事件源才能写入事件;在使用源写入第一个条目之前,必须创建并配置事件源。

在安装应用程序期间Create新的事件源。 这允许操作系统有时间刷新其已注册事件源及其配置的列表。 如果操作系统尚未刷新其事件源列表,并且您尝试使用新源编写事件,则写入操作将失败。 可以使用 或使用 CreateEventSource 方法配置新源EventLogInstaller。 必须在计算机上具有管理权限才能创建新的事件源。

可以为现有事件日志或新的事件日志创建事件源。 为新事件日志创建新源时,系统会为该日志注册源,但在写入第一个条目之前不会创建该日志。

若要安装事件日志,请创建继承自 Installer的项目安装程序类,并将类的 设置为 RunInstallerAttributetrue。 在项目中,为应用程序将写入的每个事件日志创建 , EventLogInstaller 并将 实例添加到项目安装程序类。

调用 Installutil.exe (安装程序工具) 时,它将查看 RunInstallerAttributetrue如果是 ,该工具将安装集合中Installers与项目安装程序关联的所有项。 如果 RunInstallerAttributefalse,该工具将忽略项目安装程序。

在将 实例Installers添加到项目安装程序的集合之前,但在安装程序工具运行之前,可以修改 的其他属性EventLogInstaller。 如果应用程序将写入事件日志, Source 则必须设置 属性。

使用 EventLogInstaller 为新的或现有的事件日志注册新的源;请勿使用 EventLogInstaller 来更改现有源。 类 EventLogInstaller 不会修改现有源的配置属性以匹配指定的安装属性。 如果 Source 属性与在计算机上为其他事件日志注册的源名称匹配,则 Install 方法将引发异常。 Install如果Source属性与已在 属性中指定的同一事件日志中注册的源名称匹配,则方法不会注册源Log

可以使用事件类别和消息字符串的本地化资源文件注册事件源。 应用程序可以使用资源标识符写入事件日志条目,而不是指定实际字符串。 事件查看器使用资源标识符根据当前语言设置查找并显示本地化资源文件中的相应字符串。 可以为事件类别、消息和参数插入字符串注册单独的文件,也可以为所有三种类型的字符串注册相同的资源文件。 CategoryCount使用 、CategoryResourceFileMessageResourceFileParameterResourceFile 属性将源配置为将本地化条目写入事件日志。 如果应用程序将字符串值直接写入事件日志,则无需设置这些属性。

必须为编写本地化条目或写入直接字符串配置源。 如果应用程序使用资源标识符和字符串值写入条目,则必须注册两个单独的源。 例如,使用资源文件配置一个源,然后在 方法中 WriteEvent 使用该源将使用资源标识符的条目写入事件日志。 Create不带资源文件的其他源,然后在 方法中WriteEntry使用该源将字符串直接写入使用该源的事件日志。

通常,你不会从代码中调用 类的方法 EventLogInstaller ;通常仅由 Installutil.exe 调用。 该工具在安装过程中自动调用 Install 方法。 如有必要,它会通过为生成异常的对象调用 Rollback 方法来回退失败。

构造函数

EventLogInstaller()

初始化 EventLogInstaller 类的新实例。

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。

(继承自 Component)
CategoryCount

获取或设置类别资源文件中类别的数目。

CategoryResourceFile

获取或设置包含源的类别字符串的资源文件的路径。

Container

获取包含 IContainerComponent

(继承自 Component)
Context

获取或设置关于当前安装的信息。

(继承自 Installer)
DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。

(继承自 Component)
HelpText

获取安装程序集合中所有安装程序的帮助文字。

(继承自 Installer)
Installers

获取该安装程序包含的安装程序的集合。

(继承自 Installer)
Log

获取或设置要向其设置源的日志的名称。

MessageResourceFile

获取或设置资源文件的路径,该文件包含源的消息格式字符串。

ParameterResourceFile

获取或设置资源文件的路径,该文件包含源的消息参数字符串。

Parent

获取或设置包含该安装程序所属的集合的安装程序。

(继承自 Installer)
Site

获取或设置 ComponentISite

(继承自 Component)
Source

获取或设置要在日志中注册的源名称。

UninstallAction

获取或设置一个值,以指示 Installutil.exe(安装程序工具)在卸载时应删除事件日志还是保留其安装状态。

方法

Commit(IDictionary)

在派生类中重写时,完成安装事务。

(继承自 Installer)
CopyFromComponent(IComponent)

复制安装时所需要的 EventLog 组件(与事件日志对应)的属性值。

CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。

(继承自 MarshalByRefObject)
Dispose()

释放由 Component 使用的所有资源。

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。

(继承自 Component)
Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetLifetimeService()
已过时.

检索控制此实例的生存期策略的当前生存期服务对象。

(继承自 MarshalByRefObject)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。

(继承自 Component)
GetType()

获取当前实例的 Type

(继承自 Object)
InitializeLifetimeService()
已过时.

获取生存期服务对象来控制此实例的生存期策略。

(继承自 MarshalByRefObject)
Install(IDictionary)

执行安装并将事件日志信息写入注册表。

IsEquivalentInstaller(ComponentInstaller)

确定安装程序和指定的另一个安装程序是否引用同一个源。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。

(继承自 MarshalByRefObject)
OnAfterInstall(IDictionary)

引发 AfterInstall 事件。

(继承自 Installer)
OnAfterRollback(IDictionary)

引发 AfterRollback 事件。

(继承自 Installer)
OnAfterUninstall(IDictionary)

引发 AfterUninstall 事件。

(继承自 Installer)
OnBeforeInstall(IDictionary)

引发 BeforeInstall 事件。

(继承自 Installer)
OnBeforeRollback(IDictionary)

引发 BeforeRollback 事件。

(继承自 Installer)
OnBeforeUninstall(IDictionary)

引发 BeforeUninstall 事件。

(继承自 Installer)
OnCommitted(IDictionary)

引发 Committed 事件。

(继承自 Installer)
OnCommitting(IDictionary)

引发 Committing 事件。

(继承自 Installer)
Rollback(IDictionary)

通过回滚安装过程写入注册表的事件日志信息,将计算机还原为安装前的状态。

ToString()

返回包含 Component 的名称的 String(如果有)。 不应重写此方法。

(继承自 Component)
Uninstall(IDictionary)

通过从注册表中移除事件日志信息来移除安装。

事件

AfterInstall

Installers 属性中的所有安装程序的 Install(IDictionary) 方法都运行后发生。

(继承自 Installer)
AfterRollback

在回滚 Installers 属性中所有安装程序的安装后发生。

(继承自 Installer)
AfterUninstall

Installers 属性中所有安装程序都执行它们的卸载操作后发生。

(继承自 Installer)
BeforeInstall

在安装程序集合中每个安装程序的 Install(IDictionary) 方法运行前发生。

(继承自 Installer)
BeforeRollback

在回滚 Installers 属性中的安装程序前发生。

(继承自 Installer)
BeforeUninstall

Installers 属性中的安装程序执行它们的卸载操作前发生。

(继承自 Installer)
Committed

Installers 属性中的所有安装程序均提交它们的安装后发生。

(继承自 Installer)
Committing

Installers 属性中的安装程序提交它们的安装前发生。

(继承自 Installer)
Disposed

在通过调用 Dispose() 方法释放组件时发生。

(继承自 Component)

适用于

另请参阅