EventInstance 생성자

정의

언어 중립 정보로 이벤트 로그 엔트리를 정의하여 EventInstance 클래스의 새 인스턴스를 초기화합니다.

오버로드

EventInstance(Int64, Int32)

이벤트 엔트리의 지역화된 메시지 및 범주 텍스트에 대한 지정된 리소스 식별자를 사용하여 EventInstance 클래스의 새 인스턴스를 초기화합니다.

EventInstance(Int64, Int32, EventLogEntryType)

지역화된 메시지의 지정된 리소스 식별자, 이벤트 엔트리의 범주 텍스트 및 지정된 이벤트 로그 엔트리 형식을 사용하여 EventInstance 클래스의 새 인스턴스를 초기화합니다.

EventInstance(Int64, Int32)

Source:
EventData.cs
Source:
EventData.cs
Source:
EventData.cs

이벤트 엔트리의 지역화된 메시지 및 범주 텍스트에 대한 지정된 리소스 식별자를 사용하여 EventInstance 클래스의 새 인스턴스를 초기화합니다.

public:
 EventInstance(long instanceId, int categoryId);
public EventInstance (long instanceId, int categoryId);
new System.Diagnostics.EventInstance : int64 * int -> System.Diagnostics.EventInstance
Public Sub New (instanceId As Long, categoryId As Integer)

매개 변수

instanceId
Int64

이벤트 소스의 메시지 리소스 파일에 정의된 문자열에 해당하는 리소스 식별자입니다.

categoryId
Int32

이벤트 소스의 범주 리소스 파일에 정의된 문자열에 해당하는 리소스 식별자입니다. 이벤트 범주가 없는 경우 0입니다.

예외

instanceId 매개 변수는 음수 값이거나 UInt32.MaxValue보다 큰 값입니다.

또는

categoryId 매개 변수는 음수 값이거나 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  
.  

설명

정보 항목을 이벤트 로그에 쓰려면 를 초기화 EventInstance 하고 메서드에 WriteEvent 전달합니다. 를 instanceId 원본의 해당 MessageResourceFile 속성에 있는 이벤트 메시지의 리소스 식별자로 설정합니다. categoryId 를 숫자 범주 값으로 설정하거나 원본 속성에서 이벤트 범주 CategoryResourceFile 의 리소스 식별자를 설정합니다. 이벤트 범주가 없도록 를 0으로 설정합니다categoryId. EntryType 새 instance 대한 속성은 기본적으로 로 Information 설정됩니다.

이벤트 뷰어 리소스 식별자를 사용하여 원본에 대한 지역화된 리소스 파일의 해당 문자열을 표시합니다. 리소스 식별자를 사용하여 이벤트를 작성하려면 먼저 해당 리소스 파일에 원본을 등록해야 합니다.

추가 정보

적용 대상

EventInstance(Int64, Int32, EventLogEntryType)

Source:
EventData.cs
Source:
EventData.cs
Source:
EventData.cs

지역화된 메시지의 지정된 리소스 식별자, 이벤트 엔트리의 범주 텍스트 및 지정된 이벤트 로그 엔트리 형식을 사용하여 EventInstance 클래스의 새 인스턴스를 초기화합니다.

public:
 EventInstance(long instanceId, int categoryId, System::Diagnostics::EventLogEntryType entryType);
public EventInstance (long instanceId, int categoryId, System.Diagnostics.EventLogEntryType entryType);
new System.Diagnostics.EventInstance : int64 * int * System.Diagnostics.EventLogEntryType -> System.Diagnostics.EventInstance
Public Sub New (instanceId As Long, categoryId As Integer, entryType As EventLogEntryType)

매개 변수

instanceId
Int64

이벤트 소스의 메시지 리소스 파일에 정의된 문자열에 해당하는 리소스 식별자입니다.

categoryId
Int32

이벤트 소스의 범주 리소스 파일에 정의된 문자열에 해당하는 리소스 식별자입니다. 이벤트 범주가 없는 경우 0입니다.

entryType
EventLogEntryType

이벤트의 형식을 나타내는 EventLogEntryType 값입니다.

예외

entryType는 유효한 EventLogEntryType 값이 아닙니다.

instanceId 는 음수 값이거나 UInt32.MaxValue보다 큰 값입니다.

또는

categoryId 는 음수 값이거나 UInt16.MaxValue보다 큰 값입니다.

예제

다음 코드 예제에서는 이벤트 로그 myNewLog에 두 개의 감사 이벤트 항목을 씁니다. 코드 예제에서는 로컬 컴퓨터에 없는 경우 새 이벤트 원본 및 새 이벤트 로그를 만듭니다. 이벤트 메시지 텍스트는 리소스 파일의 리소스 식별자를 사용하여 지정됩니다.

// Create the event source if it does not exist.
String^ sourceName = "SampleApplicationSource";
if (  !EventLog::SourceExists( sourceName ) )
{
   
   // Call a local method to register the event log source
   // for the event log "myNewLog."  Use the resource file
   // EventLogMsgs.dll in the current directory for message text.
   String^ messageFile = String::Format( "{0}\\{1}", System::Environment::CurrentDirectory, "EventLogMsgs.dll" );
   CreateEventSourceSample1( messageFile );
}

// Get the event log corresponding to the existing source.
String^ myLogName = EventLog::LogNameFromSourceName( sourceName, "." );
EventLog^ myEventLog = gcnew EventLog( myLogName,".",sourceName );

// Define two audit events.
// The message identifiers correspond to the message text in the
// message resource file defined for the source.
EventInstance ^ myAuditSuccessEvent = gcnew EventInstance( AuditSuccessMsgId,0,EventLogEntryType::SuccessAudit );
EventInstance ^ myAuditFailEvent = gcnew EventInstance( AuditFailedMsgId,0,EventLogEntryType::FailureAudit );

// Insert the method name into the event log message.
array<String^>^insertStrings = {"EventLogSamples.WriteEventSample1"};

// Write the events to the event log.
myEventLog->WriteEvent( myAuditSuccessEvent, insertStrings );

// Append binary data to the audit failure event entry.
array<Byte>^binaryData = {3,4,5,6};
myEventLog->WriteEvent( myAuditFailEvent, binaryData, insertStrings );

// Create the event source if it does not exist.
string sourceName = "SampleApplicationSource";
if(!EventLog.SourceExists(sourceName))
{
    // Call a local method to register the event log source
    // for the event log "myNewLog."  Use the resource file
    // EventLogMsgs.dll in the current directory for message text.

    string messageFile =  String.Format("{0}\\{1}",
        System.Environment.CurrentDirectory,
        "EventLogMsgs.dll");

    CreateEventSourceSample1(messageFile);
}

// Get the event log corresponding to the existing source.
string myLogName = EventLog.LogNameFromSourceName(sourceName,".");

EventLog myEventLog = new EventLog(myLogName, ".", sourceName);

// Define two audit events.

// The message identifiers correspond to the message text in the
// message resource file defined for the source.
EventInstance myAuditSuccessEvent = new EventInstance(AuditSuccessMsgId, 0, EventLogEntryType.SuccessAudit);
EventInstance myAuditFailEvent = new EventInstance(AuditFailedMsgId, 0, EventLogEntryType.FailureAudit);

// Insert the method name into the event log message.
string [] insertStrings = {"EventLogSamples.WriteEventSample1"};

// Write the events to the event log.

myEventLog.WriteEvent(myAuditSuccessEvent, insertStrings);

// Append binary data to the audit failure event entry.
byte [] binaryData = { 3, 4, 5, 6 };
myEventLog.WriteEvent(myAuditFailEvent, binaryData, insertStrings);

           Dim sourceName As String = "SampleApplicationSource"

           ' Create the event source if it does not exist.
           If Not EventLog.SourceExists(sourceName)
  
               ' Call a local method to register the event log source
               ' for the event log "myNewLog."  Use the resource file
               ' EventLogMsgs.dll in the current directory for message text.

               Dim messageFile As String =  String.Format("{0}\\{1}", _
                   System.Environment.CurrentDirectory, _
                   "EventLogMsgs.dll")

               CreateEventSourceSample1(messageFile)
           End If 

           ' Get the event log corresponding to the existing source.
           Dim myLogName As String = EventLog.LogNameFromSourceName(sourceName,".")
       
           Dim myEventLog As EventLog = new EventLog(myLogName, ".", sourceName)

           ' Define two audit events.
           Dim myAuditSuccessEvent As EventInstance = new EventInstance(AuditSuccessMsgId, 0, EventLogEntryType.SuccessAudit)
           Dim myAuditFailEvent As EventInstance = new EventInstance(AuditFailedMsgId, 0, EventLogEntryType.FailureAudit)

           ' Insert the method name into the event log message.
           Dim insertStrings() As String = {"EventLogSamples.WriteEventSample1"}
           
           ' Write the events to the event log.

           myEventLog.WriteEvent(myAuditSuccessEvent, insertStrings)

           ' Append binary data to the audit failure event entry.
           Dim binaryData() As Byte = { 7, 8, 9, 10 }
           myEventLog.WriteEvent(myAuditFailEvent, binaryData, insertStrings)

코드 예제에서는 리소스 라이브러리 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  
.  

설명

이벤트 로그에 항목을 쓰려면 를 초기화 EventInstance 하고 메서드에 WriteEvent 전달합니다. 를 instanceId 원본의 해당 MessageResourceFile 속성에 있는 이벤트 메시지의 리소스 식별자로 설정합니다. categoryId 를 숫자 범주 값으로 설정하거나 원본 속성에서 이벤트 범주 CategoryResourceFile 의 리소스 식별자를 설정합니다. 이벤트 범주가 없도록 를 0으로 설정합니다categoryId.

이벤트 뷰어 리소스 식별자를 사용하여 원본에 대한 지역화된 리소스 파일의 해당 문자열을 표시합니다. 리소스 식별자를 사용하여 이벤트를 작성하려면 먼저 해당 리소스 파일에 원본을 등록해야 합니다.

entryType 미리 정의된 항목 유형 중 하나로 설정합니다. 이벤트 뷰어 이벤트 유형을 사용하여 이벤트 로그의 목록 보기에 표시할 아이콘을 결정합니다.

추가 정보

적용 대상