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

範例

下列程式代碼範例會設定新事件來源的安裝屬性。 程式代碼範例會設定來源名稱和事件記錄檔名稱,並將 加入 EventLogInstallerInstallers 集合。

#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 新的事件來源。 這可讓操作系統重新整理其已註冊事件來源及其組態的清單。 如果操作系統尚未重新整理其事件來源清單,而且您嘗試使用新來源寫入事件,則寫入作業將會失敗。 您可以使用 來設定新的來源 EventLogInstaller,或使用 CreateEventSource 方法。 您必須擁有計算機上的系統管理許可權,才能建立新的事件來源。

您可以為現有的事件記錄檔或新的事件記錄檔建立事件來源。 當您為新的事件記錄檔建立新的來源時,系統會註冊該記錄檔的來源,但在寫入第一個專案之前,不會建立記錄檔。

若要安裝事件記錄檔,請建立繼承自 Installer的項目安裝程式類別,並將 類別的 設定 RunInstallerAttributetrue。 在您的專案中,針對您的應用程式將寫入的每個事件記錄檔建立, EventLogInstaller 並將實例新增至您的專案安裝程序類別。

呼叫 Installutil.exe (安裝程式工具) 時,它會查看 RunInstallerAttributetrue如果是 ,此工具會安裝與專案安裝程式相關聯之集合中的所有Installers專案。 如果 RunInstallerAttributefalse,此工具會忽略專案安裝程式。

您可以在將 實例新增至Installers專案安裝程式的集合之前或之後修改 的其他屬性EventLogInstaller,但在安裝程式工具執行之前。 如果您的應用程式將寫入事件記錄檔, Source 您必須設定 屬性。

使用 EventLogInstaller 來為新的或現有的事件記錄檔註冊新的來源;請勿使用 EventLogInstaller 來變更現有的來源。 類別 EventLogInstaller 不會修改現有來源的組態屬性,以符合指定的安裝屬性。 如果 Source 屬性符合計算機上針對不同事件記錄檔註冊的來源名稱,方法Install會擲回例外狀況。 如果 Source 屬性符合已在 屬性中指定的Log相同事件記錄檔註冊的來源名稱,則Install方法不會註冊來源。

您可以使用事件類別目錄和訊息字串的當地語系化資源檔來註冊事件來源。 您的應用程式可以使用資源識別碼來寫入事件記錄專案,而不是指定實際的字串。 事件檢視器 會使用資源標識符,根據目前的語言設定,從本地化的資源文件尋找並顯示對應的字串。 您可以為事件類別目錄、訊息和參數插入字串註冊個別的檔案,也可以針對這三種類型的字串註冊相同的資源檔。 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。

(繼承來源 MarshalByRefObject)
Dispose()

釋放 Component 所使用的所有資源。

(繼承來源 Component)
Dispose(Boolean)

釋放 Component 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

(繼承來源 Component)
Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetLifetimeService()
已淘汰.

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。

(繼承來源 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)

適用於

另請參閱