EventInstance.CategoryId 속성

정의

애플리케이션에 정의된 이벤트 엔트리의 범주를 지정하는 리소스 식별자를 가져오거나 설정합니다.

public:
 property int CategoryId { int get(); void set(int value); };
public int CategoryId { get; set; }
member this.CategoryId : int with get, set
Public Property CategoryId As Integer

속성 값

이벤트 소스의 범주 리소스 파일에 정의된 문자열에 해당하는 리소스 식별자의 숫자 범주 값 또는 리소스 식별자입니다. 기본값은 0이며 이벤트 엔트리에 대해 범주가 표시되지 않을 것임을 나타냅니다.

예외

속성은 음수 값 또는 UInt16.MaxValue보다 큰 값으로 설정됩니다.

예제

다음 코드 예제에서는 정보 이벤트 항목을 작성한 다음 를 다시 사용하여 EventInstance 경고 이벤트에 대한 항목을 기존 이벤트 로그에 씁니다. 이벤트 메시지 텍스트는 메시지 리소스 파일의 리소스 식별자를 사용하여 지정됩니다. 코드 예제에서는 해당 메시지 리소스 파일이 원본에 대해 등록되었다고 가정합니다.

// Ensure that the source has already been registered using
// EventLogInstaller or EventLog.CreateEventSource.
String^ sourceName = "SampleApplicationSource";
if ( EventLog::SourceExists( sourceName ) )
{
   // Define an informational event with no category.
   // The message identifier corresponds to the message text in the
   // message resource file defined for the source.
   EventInstance ^ myEvent = gcnew EventInstance( UpdateCycleCompleteMsgId,0 );

   // Write the event to the event log using the registered source.
   EventLog::WriteEvent( sourceName, myEvent, 0 );

   // Reuse the event data instance for another event entry.
   // Set the entry category and message identifiers for
   // the appropriate resource identifiers in the resource files
   // for the registered source.  Set the event type to Warning.
   myEvent->CategoryId = RefreshCategoryMsgId;
   myEvent->EntryType = EventLogEntryType::Warning;
   myEvent->InstanceId = ServerConnectionDownMsgId;

   // Write the event to the event log using the registered source.
   // Insert the machine name into the event message text.
   array<String^>^ss = {Environment::MachineName};
   EventLog::WriteEvent( sourceName, myEvent, ss );
}
else
{
   Console::WriteLine( "Warning - event source {0} not registered", sourceName );
}

// Ensure that the source has already been registered using
// EventLogInstaller or EventLog.CreateEventSource.

string sourceName = "SampleApplicationSource";
if(EventLog.SourceExists(sourceName))
{
    // Define an informational event with no category.
    // The message identifier corresponds to the message text in the
    // message resource file defined for the source.
    EventInstance myEvent = new EventInstance(UpdateCycleCompleteMsgId, 0);

    // Write the event to the event log using the registered source.
    EventLog.WriteEvent(sourceName, myEvent);

    // Reuse the event data instance for another event entry.
    // Set the entry category and message identifiers for
    // the appropriate resource identifiers in the resource files
    // for the registered source.  Set the event type to Warning.

    myEvent.CategoryId = RefreshCategoryMsgId;
    myEvent.EntryType = EventLogEntryType.Warning;
    myEvent.InstanceId = ServerConnectionDownMsgId;

    // Write the event to the event log using the registered source.
    // Insert the machine name into the event message text.
    EventLog.WriteEvent(sourceName, myEvent, Environment.MachineName);
}
else
{
    Console.WriteLine("Warning - event source {0} not registered",
        sourceName);
}
' Ensure that the source has already been registered using
' EventLogInstaller or EventLog.CreateEventSource.
Dim sourceName as String = "SampleApplicationSource"
If EventLog.SourceExists(sourceName)
    
    ' Define an informational event with no category.
    ' The message identifier corresponds to the message text in the
    ' message resource file defined for the source.
    Dim myEvent As EventInstance = New EventInstance(UpdateCycleCompleteMsgId, 0)
    ' Write the event to the event log using the registered source.
    EventLog.WriteEvent(sourceName, myEvent)

    ' Reuse the event data instance for another event entry.
    ' Set the entry category and message identifiers for
    ' the appropriate resource identifiers in the resource files
    ' for the registered source.  Set the event type to Warning.

    myEvent.CategoryId = RefreshCategoryMsgId
    myEvent.EntryType = EventLogEntryType.Warning
    myEvent.InstanceId = ServerConnectionDownMsgId

    ' Write the event to the event log using the registered source.
    ' Insert the machine name into the event message text.
    EventLog.WriteEvent(sourceName, myEvent, Environment.MachineName)

Else 
    Console.WriteLine("Warning - event source {0} not registered", _
        sourceName)
End If

코드 예제에서는 리소스 라이브러리 EventLogMsgs.dll 내장 다음 메시지 텍스트 파일을 사용 합니다. 메시지 텍스트 파일은 메시지 리소스 파일 생성 되는 원본. 메시지 텍스트 파일의 리소스 식별자와 범주, 이벤트 메시지 및 매개 변수 삽입 문자열에 대 한 텍스트를 정의합니다.

; // 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  
.  

설명

이벤트 로그 범주는 이벤트를 필터링 하거나 이벤트에 대 한 정보를 제공 하는 애플리케이션 정의 값입니다. 예를 들어, 애플리케이션 다양 한 구성 요소 또는 다른 작업에 대 한 별도 범주를 정의할 수 있습니다.

CategoryId 속성을 설정하여 항목에 대해 이벤트 뷰어 표시하는 범주를 지정합니다. 이벤트 뷰어 범주를 숫자 값으로 표시하거나 를 리소스 식별자로 사용하여 CategoryId 현재 언어 설정에 따라 지역화된 범주 문자열을 표시할 수 있습니다.

이벤트 뷰어 지역화된 범주 문자열을 표시하려면 범주 리소스 파일로 구성된 이벤트 원본을 사용하고 를 범주 리소스 파일의 리소스 식별자로 설정 CategoryId 해야 합니다. 이벤트 원본에 구성된 범주 리소스 파일이 없거나 지정된 CategoryId 가 범주 리소스 파일의 문자열을 인덱싱하지 않는 경우 이벤트 뷰어 해당 항목의 숫자 범주 값을 표시합니다.

리소스 식별자를 사용하여 이벤트 범주를 작성하기 전에 해당 리소스 파일에 원본을 등록해야 합니다. 또는 EventSourceCreationData 클래스를 사용하여 EventLogInstaller 리소스 파일의 범주 문자열 수와 함께 범주 리소스 파일을 구성합니다. 리소스 파일에서 범주 문자열을 정의할 때 범주 리소스 식별자는 구성된 CategoryCount 속성 값까지 1부터 연속적으로 번호가 매겨져야 합니다.

이벤트 범주는 선택 사항입니다. 애플리케이션 범주를 사용 하지 않는 경우 설정 하지 마십시오는 CategoryId 이벤트 로그 항목에 대 한 합니다.

이벤트 메시지를 정의하고 이벤트 리소스 파일을 빌드하는 방법에 대한 자세한 내용은 플랫폼 SDK 설명서의 메시지 컴파일러 문서를 참조하세요. 리소스 파일에서 이벤트 범주를 정의하는 방법에 대한 자세한 내용은 플랫폼 SDK의 "이벤트 범주" 항목을 참조하세요.

적용 대상

추가 정보