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(安裝程式工具EventLogInstaller )。The 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.

當您EventLogInstaller的應用程式寫入事件記錄檔時, 請使用類別, 而您的應用程式不需要使用事件記錄檔安裝程式來讀取事件記錄檔。Use 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. 您可以使用EventLogInstaller來設定新的來源, 或CreateEventSource使用方法。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的專案安裝程式類別, 並RunInstallerAttribute將類別的設定為。 trueTo 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為新的或現有的事件記錄檔註冊新的來源, 請勿使用EventLogInstaller來變更現有的來源。Use 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. 如果屬性符合針對電腦上的不同事件記錄檔註冊的來源名稱,方法會擲回例外狀況。Install SourceThe 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

取得包含 IContainerComponentGets 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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 的淺層複本 (Shallow Copy)。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 名稱的 StringReturns 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)

適用於

另請參閱