EventLogInstaller.MessageResourceFile 屬性

定義

取得或設定資源檔路徑,這個資源檔包含來源的訊息格式化字串。Gets or sets the path of the resource file that contains message formatting strings for the source.

public:
 property System::String ^ MessageResourceFile { System::String ^ get(); void set(System::String ^ value); };
[System.Runtime.InteropServices.ComVisible(false)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string MessageResourceFile { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.Runtime.InteropServices.ComVisible(false)]
public string MessageResourceFile { get; set; }
member this.MessageResourceFile : string with get, set
Public Property MessageResourceFile As String

屬性值

訊息資源檔的路徑。The path of the message resource file. 預設為空字串 ("")。The default is an empty string ("").

屬性

範例

下列程式碼範例會設定新事件來源的安裝屬性。The following code example sets the installation properties for a new event source. 此程式碼範例會設定當地語系化事件文字的事件來源名稱、事件記錄檔名稱和資源檔。The code example sets the event source name, event log name, and resource file for localized event text.

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

public:
   SampleEventLogInstaller()
   {
      
      // Create an instance of an EventLogInstaller.
      myEventLogInstaller = gcnew EventLogInstaller;
      
      // Set the source name of the event log.
      myEventLogInstaller->Source = "ApplicationEventSource";
      
      // Set the event log into which the source writes entries.
      //myEventLogInstaller.Log = "MyCustomLog";
      myEventLogInstaller->Log = "myNewLog";
      
      // Set the resource file for the event log.
      // The message strings are defined in EventLogMsgs.mc; the message 
      // identifiers used in the application must match those defined in the
      // corresponding message resource file. The messages must be built
      // into a Win32 resource library and copied to the target path on the
      // system.  
      myEventLogInstaller->CategoryResourceFile =
             Environment::SystemDirectory + "\\eventlogmsgs.dll";
      myEventLogInstaller->CategoryCount = 3;
      myEventLogInstaller->MessageResourceFile =
             Environment::SystemDirectory + "\\eventlogmsgs.dll";
      myEventLogInstaller->ParameterResourceFile =
             Environment::SystemDirectory + "\\eventlogmsgs.dll";

      // Add myEventLogInstaller to the installer collection.
      Installers->Add( myEventLogInstaller );
   }

};

int main()
{
   Console::WriteLine( "Usage: InstallUtil.exe [<install>.exe | <install>.dll]" );
}

using System;
using System.Configuration.Install;
using System.Diagnostics;
using System.ComponentModel;

[RunInstaller(true)]
public class SampleEventLogInstaller : Installer
{
    private EventLogInstaller myEventLogInstaller;

    public SampleEventLogInstaller() 
    {
        // Create an instance of an EventLogInstaller.
        myEventLogInstaller = new EventLogInstaller();

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

        // Set the event log into which the source writes entries.
        //myEventLogInstaller.Log = "MyCustomLog";
        myEventLogInstaller.Log = "myNewLog";

        // Set the resource file for the event log.
        // The message strings are defined in EventLogMsgs.mc; the message 
        // identifiers used in the application must match those defined in the
        // corresponding message resource file. The messages must be built
        // into a Win32 resource library and copied to the target path on the
        // system.  
            
        myEventLogInstaller.CategoryResourceFile =
             Environment.SystemDirectory + "\\eventlogmsgs.dll";
        myEventLogInstaller.CategoryCount = 3;
        myEventLogInstaller.MessageResourceFile =
             Environment.SystemDirectory + "\\eventlogmsgs.dll";
        myEventLogInstaller.ParameterResourceFile =
             Environment.SystemDirectory + "\\eventlogmsgs.dll";

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

    public static void Main()
    {
        Console.WriteLine("Usage: InstallUtil.exe [<install>.exe | <install>.dll]");
    }
}
   Imports System.Configuration.Install
Imports System.Diagnostics
Imports System.ComponentModel

<RunInstaller(True)>  _
Public Class SampleEventLogInstaller
   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 = "ApplicationEventSource"

      ' Set the event log into which the source writes entries.
      myEventLogInstaller.Log = "MyCustomLog"

      ' Set the resource file for the event log.
      ' The message strings are defined in EventLogMsgs.mc; the message
      ' identifiers used in the application must match those defined in the
      ' corresponding message resource file. The messages must be built
      ' into a Win32 resource library and copied to the target path on the
      ' system.

      myEventLogInstaller.CategoryResourceFile = _
          Environment.SystemDirectory + "\eventlogmsgs.dll"
      myEventLogInstaller.CategoryCount = 3
      myEventLogInstaller.MessageResourceFile = _
          Environment.SystemDirectory + "\eventlogmsgs.dll"
      myEventLogInstaller.ParameterResourceFile = _
          Environment.SystemDirectory + "\eventlogmsgs.dll"

      ' Add myEventLogInstaller to the installer collection.
      Installers.Add(myEventLogInstaller)

   End Sub

   Public Shared Sub Main()
     Console.WriteLine("Usage: InstallUtil.exe [<install>.exe | <install>.dll]")
   End Sub
End Class

此程式碼範例會使用內建于資源連結庫 EventLogMsgs 的下列郵件內文檔案。The code example uses the following message text file, built into the resource library EventLogMsgs.dll. 訊息文字檔是用來建立訊息資源檔的來源。A message text file is the source from which the message resource file is created. 訊息文字檔會定義類別目錄、事件訊息和參數插入字串的資源識別碼和文字。The message text file defines the resource identifiers and text for the category, event message, and parameter insertion strings.

; // EventLogMsgs.mc  
; // ********************************************************  
  
; // Use the following commands to build this file:  
  
; //   mc -s EventLogMsgs.mc  
; //   rc EventLogMsgs.rc  
; //   link /DLL /SUBSYSTEM:WINDOWS /NOENTRY /MACHINE:x86 EventLogMsgs.Res   
; // ********************************************************  
  
; // - Event categories -  
; // Categories must be numbered consecutively starting at 1.  
; // ********************************************************  
  
MessageId=0x1  
Severity=Success  
SymbolicName=INSTALL_CATEGORY  
Language=English  
Installation  
.  
  
MessageId=0x2  
Severity=Success  
SymbolicName=QUERY_CATEGORY  
Language=English  
Database Query  
.  
  
MessageId=0x3  
Severity=Success  
SymbolicName=REFRESH_CATEGORY  
Language=English  
Data Refresh  
.  
  
; // - Event messages -  
; // *********************************  
  
MessageId = 1000  
Severity = Success  
Facility = Application  
SymbolicName = AUDIT_SUCCESS_MESSAGE_ID_1000  
Language=English  
My application message text, in English, for message id 1000, called from %1.  
.  
  
MessageId = 1001  
Severity = Warning  
Facility = Application  
SymbolicName = AUDIT_FAILED_MESSAGE_ID_1001  
Language=English  
My application message text, in English, for message id 1001, called from %1.  
.  
  
MessageId = 1002  
Severity = Success  
Facility = Application  
SymbolicName = GENERIC_INFO_MESSAGE_ID_1002  
Language=English  
My generic information message in English, for message id 1002.  
.  
  
MessageId = 1003  
Severity = Warning  
Facility = Application  
SymbolicName = GENERIC_WARNING_MESSAGE_ID_1003  
Language=English  
My generic warning message in English, for message id 1003, called from %1.  
.  
  
MessageId = 1004  
Severity = Success  
Facility = Application  
SymbolicName = UPDATE_CYCLE_COMPLETE_MESSAGE_ID_1004  
Language=English  
The update cycle is complete for %%5002.  
.  
  
MessageId = 1005  
Severity = Warning  
Facility = Application  
SymbolicName = SERVER_CONNECTION_DOWN_MESSAGE_ID_1005  
Language=English  
The refresh operation did not complete because the connection to server %1 could not be established.  
.  
  
; // - Event log display name -  
; // ********************************************************  
  
MessageId = 5001  
Severity = Success  
Facility = Application  
SymbolicName = EVENT_LOG_DISPLAY_NAME_MSGID  
Language=English  
Sample Event Log  
.  
  
; // - Event message parameters -  
; //   Language independent insertion strings  
; // ********************************************************  
  
MessageId = 5002  
Severity = Success  
Facility = Application  
SymbolicName = EVENT_LOG_SERVICE_NAME_MSGID  
Language=English  
SVC_UPDATE.EXE  
.  

備註

您可以使用屬性來設定事件記錄檔來源, 以撰寫當地語系化的事件訊息。 MessageResourceFileUse the MessageResourceFile property to configure an event log source to write localized event messages. 事件訊息是應用程式定義的字串, 會向使用者描述事件。Event messages are application-defined strings that describe the event to the user.

您的應用程式可以使用資源識別碼來寫入事件記錄檔專案。Your application can write event log entries using resource identifiers. 資源識別碼會為位於的MessageResourceFile訊息編制索引。A resource identifier indexes a message located in the MessageResourceFile. 事件檢視器會使用資源識別碼, 根據目前的語言設定, 從當地語系化的資源檔中尋找和顯示對應的字串。The Event Viewer uses the resource identifier to find and display the corresponding string from the localized resource file based on current language settings.

事件來源必須設定為寫入當地語系化的專案或撰寫直接字串。The event source must be configured either for writing localized entries or for writing direct strings. WriteEvent使用方法, 針對設定了訊息資源檔的來源, 寫入當地語系化的專案。Use the WriteEvent method to write localized entries for a source configured with a message resource file.

如果您的應用程式會直接寫入事件訊息字串, 而不是使用當地語系化資源檔中的資源識別碼, 請勿MessageResourceFile設定屬性。If your application writes event message strings directly, rather than using a resource identifier in a localized resource file, do not set the MessageResourceFile property.

MachineName如果屬性不是本機電腦識別碼 ("."), 則 .NET Framework 會假設資源檔是在遠端電腦上。If the MachineName property is not the local computer identifier ("."), the .NET Framework assumes that the resource file is on a remote computer. > \ \ \ > \如果屬性值包含磁碟機號, 則會假設資源檔位於 < machinename < drive $ share (例如 \server MessageResourceFile\c $)。If the MessageResourceFile property value contains a drive letter, the resource file is assumed to be on the \\<machinename>\<drive>$ share (for example, \\server\c$). 如果值包含字串% systemroot%, 則會\假設資源檔位於\< machinename>\admin $ 共用上 ( \例如 \server\admin $)。If the value contains the string %systemroot%, the resource file is assumed to be on the \\<machinename>\admin$ share (for example, \\server\admin$).

如需定義事件訊息和建立事件資源檔的詳細資訊, 請參閱 Platform SDK 檔中的「訊息編譯器」 http://msdn.microsoft.com主題, 網址為。For details about defining event messages and building event resource files, see the "Message Compiler" topic in the Platform SDK documentation at http://msdn.microsoft.com.

適用於

另請參閱