EventLog.WriteEvent 메서드

정의

이벤트 로그에 지역화된 이벤트 엔트리를 씁니다.

오버로드

WriteEvent(String, EventInstance, Object[])

지정한 등록된 이벤트 소스를 사용하여 지정된 이벤트 데이터와 메시지 대체 문자열이 포함된 이벤트 로그 엔트리를 씁니다.

WriteEvent(EventInstance, Object[])

이벤트 로그에 지역화된 엔트리를 씁니다.

WriteEvent(EventInstance, Byte[], Object[])

지정된 이벤트 데이터, 메시지 대체 문자열 및 관련 이진 데이터가 포함된 이벤트 로그 엔트리를 씁니다.

WriteEvent(String, EventInstance, Byte[], Object[])

지정한 등록된 이벤트 소스를 사용하여 지정된 이벤트 데이터, 메시지 대체 문자열 및 관련 이진 데이터가 포함된 이벤트 로그 엔트리를 씁니다.

WriteEvent(String, EventInstance, Object[])

지정한 등록된 이벤트 소스를 사용하여 지정된 이벤트 데이터와 메시지 대체 문자열이 포함된 이벤트 로그 엔트리를 씁니다.

public:
 static void WriteEvent(System::String ^ source, System::Diagnostics::EventInstance ^ instance, ... cli::array <System::Object ^> ^ values);
public static void WriteEvent (string source, System.Diagnostics.EventInstance instance, params object[] values);
static member WriteEvent : string * System.Diagnostics.EventInstance * obj[] -> unit
Public Shared Sub WriteEvent (source As String, instance As EventInstance, ParamArray values As Object())

매개 변수

source
String

지정된 컴퓨터의 애플리케이션에 등록된 이벤트 원본의 이름입니다.

instance
EventInstance

지역화된 이벤트 로그 항목을 나타내는 EventInstance 인스턴스입니다.

values
Object[]

이벤트 로그 항목의 메시지 텍스트로 병합될 문자열의 배열입니다.

예외

source 값이 빈 문자열("")인 경우

또는

source 값이 null입니다.

또는

instance.InstanceId 가 0보다 작거나 UInt16.MaxValue보다 큽니다.

또는

values의 요소가 256개가 넘는 경우

또는

values 요소 중 하나가 32766바이트보다 긴 경우

또는

소스 이름 때문에 레지스트리 키 경로가 254자를 넘는 경우

instance이(가) null인 경우

이벤트 로그의 레지스트리 키를 열 수 없는 경우

이벤트 로그에 이벤트 엔트리를 쓸 때 운영 체제에서 오류를 보고한 경우. Windows 오류 코드를 사용할 수 없습니다.

예제

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

String^ sourceName = "SampleApplicationSource";
if ( EventLog::SourceExists( sourceName ) )
{
   
   // Define an informational event and a warning event.
   // The message identifiers correspond to the message text in the
   // message resource file defined for the source.
   EventInstance ^ myInfoEvent = gcnew EventInstance( InformationMsgId,0,EventLogEntryType::Information );
   EventInstance ^ myWarningEvent = gcnew EventInstance( WarningMsgId,0,EventLogEntryType::Warning );
   
   // Insert the method name into the event log message.
   array<String^>^insertStrings = {"EventLogSamples.WriteEventSample2"};
   
   // Write the events to the event log.
   EventLog::WriteEvent( sourceName, myInfoEvent, 0 );
   
   // Append binary data to the warning event entry.
   array<Byte>^binaryData = {7,8,9,10};
   EventLog::WriteEvent( sourceName, myWarningEvent, binaryData, insertStrings );
}
else
{
   Console::WriteLine( "Warning - event source {0} not registered", sourceName );
}

string sourceName = "SampleApplicationSource";
if(EventLog.SourceExists(sourceName))
{

    // Define an informational event and a warning event.

    // The message identifiers correspond to the message text in the
    // message resource file defined for the source.
    EventInstance myInfoEvent = new EventInstance(InformationMsgId, 0, EventLogEntryType.Information);
    EventInstance myWarningEvent = new EventInstance(WarningMsgId, 0, EventLogEntryType.Warning);

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

    // Write the events to the event log.

    EventLog.WriteEvent(sourceName, myInfoEvent);

    // Append binary data to the warning event entry.
    byte [] binaryData = { 7, 8, 9, 10 };
    EventLog.WriteEvent(sourceName, myWarningEvent, binaryData, insertStrings);
}
else
{
    Console.WriteLine("Warning - event source {0} not registered",
        sourceName);
}
           Dim sourceName As String = "SampleApplicationSource"
           If EventLog.SourceExists(sourceName)
  
               ' Define an informational event and a warning event.

               ' The message identifiers correspond to the message text in the
               ' message resource file defined for the source.
               Dim myInfoEvent As EventInstance = new EventInstance(InformationMsgId, 0, EventLogEntryType.Information)
               Dim myWarningEvent As EventInstance = new EventInstance(WarningMsgId, 0, EventLogEntryType.Warning)

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

               EventLog.WriteEvent(sourceName, myInfoEvent, insertStrings)

               ' Append binary data to the warning event entry.
               Dim binaryData() As Byte = { 7, 8, 9, 10 }
               EventLog.WriteEvent(sourceName, myWarningEvent, binaryData, insertStrings)
           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  
.  

설명

이 메서드를 사용하여 적절한 로그에 대한 이벤트 원본으로 이미 등록된 원본을 사용하여 지역화된 항목을 이벤트 로그에 작성합니다. 문자열 값이 아닌 리소스 식별자를 사용하여 이벤트 속성을 지정합니다. 이벤트 뷰어 리소스 식별자를 사용하여 원본에 대한 지역화된 리소스 파일의 해당 문자열을 표시합니다. 리소스 식별자를 사용하여 이벤트를 작성하기 전에 해당 리소스 파일에 원본을 등록해야 합니다.

입력 instance instance 이벤트 메시지 및 속성을 지정합니다. InstanceId 원본 메시지 리소스 파일에서 instance 정의된 메시지에 대한 입력의 를 설정합니다. 필요에 따라 입력의 instanceEntryTypeCategoryId 설정하여 이벤트 항목의 범주 및 이벤트 유형을 정의할 수 있습니다. 지역화된 메시지 텍스트에 삽입할 언어 독립적 문자열 배열을 지정할 수도 있습니다. null 이벤트 메시지에 대체 문자열에 대한 서식 지정 자리 표시자가 없는 경우 로 설정합니다values.

를 사용하기 WriteEvent전에 지정된 원본을 이벤트 로그에 등록해야 합니다. 로그에 지역화된 항목을 작성하도록 지정된 원본을 구성해야 합니다. 원본에는 최소한 메시지 리소스 파일이 정의되어야 합니다.

원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다. 애플리케이션을 설치 하는 동안 새 이벤트 원본을 만듭니다. 이렇게 하면 운영 체제가 등록된 이벤트 원본 목록과 해당 구성을 새로 고칠 수 있습니다. 운영 체제에서 이벤트 소스 목록을 새로 고치지 않은 경우 쓰려고 하면 새 원본 사용 하는 이벤트는 쓰기 작업이 실패 합니다. 사용 하 여 새 소스를 구성할 수 있습니다는 EventLogInstaller를 사용 하 여 또는 CreateEventSource 메서드. 새 이벤트 원본을 만들려면 컴퓨터에서 관리자 권한이 있어야 합니다.

원본 또는 지역화 된 엔트리를 쓰기 위한 직접 문자열을 작성 하기 위한 구성 되어야 합니다. 사용 된 WriteEntry 메서드 애플리케이션 이벤트 로그에 직접 문자열 값을 기록 하는 경우.

애플리케이션 리소스 식별자와 문자열 값을 사용 하 여 항목을 기록 하는 경우 두 개의 별도 소스를 등록 해야 합니다. 예를 들어, 리소스 파일을 한 원본을 구성 하 고 해당 소스를 사용 하 여는 WriteEvent 메서드를 이벤트 로그에 리소스 식별자를 사용 하 여 항목을 씁니다. 그런 다음 리소스 파일 없이 다른 원본을 만들고 메서드에서 해당 원본을 WriteEntry 사용하여 해당 원본을 사용하여 이벤트 로그에 직접 문자열을 작성합니다.

추가 정보

적용 대상

WriteEvent(EventInstance, Object[])

이벤트 로그에 지역화된 엔트리를 씁니다.

public:
 void WriteEvent(System::Diagnostics::EventInstance ^ instance, ... cli::array <System::Object ^> ^ values);
public void WriteEvent (System.Diagnostics.EventInstance instance, params object[] values);
[System.Runtime.InteropServices.ComVisible(false)]
public void WriteEvent (System.Diagnostics.EventInstance instance, params object[] values);
member this.WriteEvent : System.Diagnostics.EventInstance * obj[] -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.WriteEvent : System.Diagnostics.EventInstance * obj[] -> unit
Public Sub WriteEvent (instance As EventInstance, ParamArray values As Object())

매개 변수

instance
EventInstance

지역화된 이벤트 로그 항목을 나타내는 EventInstance 인스턴스입니다.

values
Object[]

이벤트 로그 항목의 메시지 텍스트로 병합될 문자열의 배열입니다.

특성

예외

SourceEventLog 속성이 설정되지 않은 경우

또는

메서드가 새 이벤트 원본을 등록하려고 시도했지만 MachineName의 컴퓨터 이름이 유효하지 않습니다.

또는

소스가 이미 다른 이벤트 로그에 등록된 경우

또는

instance.InstanceId 가 0보다 작거나 UInt16.MaxValue보다 큽니다.

또는

values의 요소가 256개가 넘는 경우

또는

values 요소 중 하나가 32766바이트보다 긴 경우

또는

소스 이름 때문에 레지스트리 키 경로가 254자를 넘는 경우

instance이(가) null인 경우

이벤트 로그의 레지스트리 키를 열 수 없는 경우

이벤트 로그에 이벤트 엔트리를 쓸 때 운영 체제에서 오류를 보고한 경우. Windows 오류 코드를 사용할 수 없습니다.

예제

다음 예제에서는 이벤트 로그 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  
.  

설명

이 메서드를 사용하여 이벤트 로그에 지역화된 항목을 작성합니다. 문자열 값이 아닌 리소스 식별자를 사용하여 이벤트 속성을 지정합니다. 이벤트 뷰어 리소스 식별자를 사용하여 에 대한 지역화된 리소스 파일의 해당 문자열을 Source표시합니다. 리소스 식별자를 사용하여 이벤트를 작성하기 전에 해당 리소스 파일에 원본을 등록해야 합니다.

입력 instance instance 이벤트 메시지 및 속성을 지정합니다. InstanceId 원본 메시지 리소스 파일에서 instance 정의된 메시지에 대한 입력의 를 설정합니다. 필요에 따라 입력의 instanceEntryTypeCategoryId 설정하여 이벤트 항목의 범주 및 이벤트 유형을 정의할 수 있습니다. 지역화된 메시지 텍스트에 삽입할 언어 독립적 문자열 배열을 지정할 수도 있습니다. null 이벤트 메시지에 대체 문자열에 대한 서식 지정 자리 표시자가 없는 경우 로 설정합니다values.

를 사용하기 WriteEvent전에 구성 요소에서 EventLog 속성을 설정 Source 해야 합니다. 로그에 지역화된 항목을 작성하도록 지정된 원본을 구성해야 합니다. 원본에는 최소한 메시지 리소스 파일이 정의되어야 합니다.

원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다. 애플리케이션을 설치 하는 동안 새 이벤트 원본을 만듭니다. 이렇게 하면 운영 체제가 등록된 이벤트 원본 목록과 해당 구성을 새로 고칠 수 있습니다. 운영 체제에서 이벤트 소스 목록을 새로 고치지 않은 경우 쓰려고 하면 새 원본 사용 하는 이벤트는 쓰기 작업이 실패 합니다. 사용 하 여 새 소스를 구성할 수 있습니다는 EventLogInstaller를 사용 하 여 또는 CreateEventSource 메서드. 새 이벤트 원본을 만들려면 컴퓨터에서 관리자 권한이 있어야 합니다.

원본 또는 지역화 된 엔트리를 쓰기 위한 직접 문자열을 작성 하기 위한 구성 되어야 합니다. 사용 된 WriteEntry 메서드 애플리케이션 이벤트 로그에 직접 문자열 값을 기록 하는 경우.

애플리케이션 리소스 식별자와 문자열 값을 사용 하 여 항목을 기록 하는 경우 두 개의 별도 소스를 등록 해야 합니다. 예를 들어, 리소스 파일을 한 원본을 구성 하 고 해당 소스를 사용 하 여는 WriteEvent 메서드를 이벤트 로그에 리소스 식별자를 사용 하 여 항목을 씁니다. 그런 다음 리소스 파일 없이 다른 원본을 만들고 메서드에서 해당 원본을 WriteEntry 사용하여 해당 원본을 사용하여 이벤트 로그에 직접 문자열을 작성합니다.

참고

원격 컴퓨터에 항목을 작성하는 경우 원격 컴퓨터에서 .NET Framework 실행하지 않는 경우 문자열 값 message 이 예상과 다를 수 있습니다. message 또한 이벤트 뷰어가 삽입 문자열로 처리하므로 문자열에 %n을 포함할 수 없습니다. 여기서 n은 정수 값(예: %1)입니다. IPv6(인터넷 프로토콜) 버전 6 주소는 이 문자 시퀀스를 포함할 수 있으므로 IPv6 주소가 포함된 이벤트 메시지를 기록할 수 없습니다.

추가 정보

적용 대상

WriteEvent(EventInstance, Byte[], Object[])

지정된 이벤트 데이터, 메시지 대체 문자열 및 관련 이진 데이터가 포함된 이벤트 로그 엔트리를 씁니다.

public:
 void WriteEvent(System::Diagnostics::EventInstance ^ instance, cli::array <System::Byte> ^ data, ... cli::array <System::Object ^> ^ values);
public void WriteEvent (System.Diagnostics.EventInstance instance, byte[] data, params object[] values);
[System.Runtime.InteropServices.ComVisible(false)]
public void WriteEvent (System.Diagnostics.EventInstance instance, byte[] data, params object[] values);
member this.WriteEvent : System.Diagnostics.EventInstance * byte[] * obj[] -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.WriteEvent : System.Diagnostics.EventInstance * byte[] * obj[] -> unit
Public Sub WriteEvent (instance As EventInstance, data As Byte(), ParamArray values As Object())

매개 변수

instance
EventInstance

지역화된 이벤트 로그 항목을 나타내는 EventInstance 인스턴스입니다.

data
Byte[]

항목과 연관된 이진 데이터를 보유하는 바이트의 배열입니다.

values
Object[]

이벤트 로그 항목의 메시지 텍스트로 병합될 문자열의 배열입니다.

특성

예외

SourceEventLog 속성이 설정되지 않은 경우

또는

메서드가 새 이벤트 원본을 등록하려고 시도했지만 MachineName의 컴퓨터 이름이 유효하지 않습니다.

또는

소스가 이미 다른 이벤트 로그에 등록된 경우

또는

instance.InstanceId 가 0보다 작거나 UInt16.MaxValue보다 큽니다.

또는

values의 요소가 256개가 넘는 경우

또는

values 요소 중 하나가 32766바이트보다 긴 경우

또는

소스 이름 때문에 레지스트리 키 경로가 254자를 넘는 경우

instance이(가) null인 경우

이벤트 로그의 레지스트리 키를 열 수 없는 경우

이벤트 로그에 이벤트 엔트리를 쓸 때 운영 체제에서 오류를 보고한 경우. Windows 오류 코드를 사용할 수 없습니다.

예제

다음 예제에서는 이벤트 로그 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  
.  

설명

이 메서드를 사용하여 이벤트 로그에 추가 이벤트별 데이터가 있는 지역화된 항목을 작성합니다. 문자열 값이 아닌 리소스 식별자를 사용하여 이벤트 속성을 지정합니다. 이벤트 뷰어 리소스 식별자를 사용하여 에 대한 지역화된 리소스 파일의 해당 문자열을 Source표시합니다. 리소스 식별자를 사용하여 이벤트를 작성하기 전에 해당 리소스 파일에 원본을 등록해야 합니다.

입력 instance instance 이벤트 메시지 및 속성을 지정합니다. InstanceId 원본 메시지 리소스 파일에서 instance 정의된 메시지에 대한 입력의 를 설정합니다. 필요에 따라 입력의 instanceEntryTypeCategoryId 설정하여 이벤트 항목의 범주 및 이벤트 유형을 정의할 수 있습니다. 지역화된 메시지 텍스트에 삽입할 언어 독립적 문자열 배열을 지정할 수도 있습니다. null 이벤트 메시지에 대체 문자열에 대한 서식 지정 자리 표시자가 없는 경우 로 설정합니다values.

이벤트에 대한 추가 세부 정보를 제공해야 하는 경우 이벤트로 이진 데이터를 지정합니다. 예를 들어 매개 변수를 data 사용하여 특정 오류에 대한 정보를 포함합니다. 이벤트 뷰어 연결된 이벤트 데이터를 해석하지 않으며, 결합된 16진수 및 텍스트 형식으로 데이터를 표시합니다. 이벤트별 데이터를 드물게 사용합니다. 유용하다고 확신하는 경우에만 포함합니다. 또한 애플리케이션 이벤트 뷰어를 독립적으로 처리할 수 정보를 저장할 이벤트 관련 데이터를 사용할 수 있습니다. 예를 들어 이벤트에 대한 뷰어를 작성하거나 이벤트 로그를 검사하고 이벤트별 데이터의 정보를 포함하는 보고서를 만드는 프로그램을 작성할 수 있습니다.

를 사용하기 WriteEvent전에 구성 요소의 EventLog 속성을 설정 Source 해야 합니다. 로그에 지역화된 항목을 작성하도록 지정된 원본을 구성해야 합니다. 원본에는 최소한 메시지 리소스 파일이 정의되어야 합니다.

원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다. 애플리케이션을 설치 하는 동안 새 이벤트 원본을 만듭니다. 이렇게 하면 운영 체제가 등록된 이벤트 원본 목록과 해당 구성을 새로 고칠 수 있습니다. 운영 체제에서 이벤트 소스 목록을 새로 고치지 않은 경우 쓰려고 하면 새 원본 사용 하는 이벤트는 쓰기 작업이 실패 합니다. 사용 하 여 새 소스를 구성할 수 있습니다는 EventLogInstaller를 사용 하 여 또는 CreateEventSource 메서드. 새 이벤트 원본을 만들려면 컴퓨터에서 관리자 권한이 있어야 합니다.

참고

를 호출WriteEvent하기 전에 instance 대한 EventLogMachineName 지정하지 않으면 로컬 컴퓨터(".")가 가정됩니다.

원본 또는 지역화 된 엔트리를 쓰기 위한 직접 문자열을 작성 하기 위한 구성 되어야 합니다. 사용 된 WriteEntry 메서드 애플리케이션 이벤트 로그에 직접 문자열 값을 기록 하는 경우.

애플리케이션 리소스 식별자와 문자열 값을 사용 하 여 항목을 기록 하는 경우 두 개의 별도 소스를 등록 해야 합니다. 예를 들어, 리소스 파일을 한 원본을 구성 하 고 해당 소스를 사용 하 여는 WriteEvent 메서드를 이벤트 로그에 리소스 식별자를 사용 하 여 항목을 씁니다. 그런 다음 리소스 파일 없이 다른 원본을 만들고 메서드에서 해당 원본을 WriteEntry 사용하여 해당 원본을 사용하여 이벤트 로그에 직접 문자열을 작성합니다.

참고

원격 컴퓨터에 항목을 작성하는 경우 원격 컴퓨터에서 .NET Framework 실행하지 않는 경우 문자열 값 message 이 예상과 다를 수 있습니다. message 또한 이벤트 뷰어가 삽입 문자열로 처리하므로 문자열에 %n을 포함할 수 없습니다. 여기서 n은 정수 값(예: %1)입니다. IPv6(인터넷 프로토콜) 버전 6 주소는 이 문자 시퀀스를 포함할 수 있으므로 IPv6 주소가 포함된 이벤트 메시지를 기록할 수 없습니다.

추가 정보

적용 대상

WriteEvent(String, EventInstance, Byte[], Object[])

지정한 등록된 이벤트 소스를 사용하여 지정된 이벤트 데이터, 메시지 대체 문자열 및 관련 이진 데이터가 포함된 이벤트 로그 엔트리를 씁니다.

public:
 static void WriteEvent(System::String ^ source, System::Diagnostics::EventInstance ^ instance, cli::array <System::Byte> ^ data, ... cli::array <System::Object ^> ^ values);
public static void WriteEvent (string source, System.Diagnostics.EventInstance instance, byte[] data, params object[] values);
static member WriteEvent : string * System.Diagnostics.EventInstance * byte[] * obj[] -> unit
Public Shared Sub WriteEvent (source As String, instance As EventInstance, data As Byte(), ParamArray values As Object())

매개 변수

source
String

지정된 컴퓨터의 애플리케이션에 등록된 이벤트 원본의 이름입니다.

instance
EventInstance

지역화된 이벤트 로그 항목을 나타내는 EventInstance 인스턴스입니다.

data
Byte[]

항목과 연관된 이진 데이터를 보유하는 바이트의 배열입니다.

values
Object[]

이벤트 로그 항목의 메시지 텍스트로 병합될 문자열의 배열입니다.

예외

source 값이 빈 문자열("")인 경우

또는

source 값이 null입니다.

또는

instance.InstanceId 가 0보다 작거나 UInt16.MaxValue보다 큽니다.

또는

values의 요소가 256개가 넘는 경우

또는

values 요소 중 하나가 32766바이트보다 긴 경우

또는

소스 이름 때문에 레지스트리 키 경로가 254자를 넘는 경우

instance이(가) null인 경우

이벤트 로그의 레지스트리 키를 열 수 없는 경우

이벤트 로그에 이벤트 엔트리를 쓸 때 운영 체제에서 오류를 보고한 경우. Windows 오류 코드를 사용할 수 없습니다.

예제

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

String^ sourceName = "SampleApplicationSource";
if ( EventLog::SourceExists( sourceName ) )
{
   
   // Define an informational event and a warning event.
   // The message identifiers correspond to the message text in the
   // message resource file defined for the source.
   EventInstance ^ myInfoEvent = gcnew EventInstance( InformationMsgId,0,EventLogEntryType::Information );
   EventInstance ^ myWarningEvent = gcnew EventInstance( WarningMsgId,0,EventLogEntryType::Warning );
   
   // Insert the method name into the event log message.
   array<String^>^insertStrings = {"EventLogSamples.WriteEventSample2"};
   
   // Write the events to the event log.
   EventLog::WriteEvent( sourceName, myInfoEvent, 0 );
   
   // Append binary data to the warning event entry.
   array<Byte>^binaryData = {7,8,9,10};
   EventLog::WriteEvent( sourceName, myWarningEvent, binaryData, insertStrings );
}
else
{
   Console::WriteLine( "Warning - event source {0} not registered", sourceName );
}

string sourceName = "SampleApplicationSource";
if(EventLog.SourceExists(sourceName))
{

    // Define an informational event and a warning event.

    // The message identifiers correspond to the message text in the
    // message resource file defined for the source.
    EventInstance myInfoEvent = new EventInstance(InformationMsgId, 0, EventLogEntryType.Information);
    EventInstance myWarningEvent = new EventInstance(WarningMsgId, 0, EventLogEntryType.Warning);

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

    // Write the events to the event log.

    EventLog.WriteEvent(sourceName, myInfoEvent);

    // Append binary data to the warning event entry.
    byte [] binaryData = { 7, 8, 9, 10 };
    EventLog.WriteEvent(sourceName, myWarningEvent, binaryData, insertStrings);
}
else
{
    Console.WriteLine("Warning - event source {0} not registered",
        sourceName);
}
           Dim sourceName As String = "SampleApplicationSource"
           If EventLog.SourceExists(sourceName)
  
               ' Define an informational event and a warning event.

               ' The message identifiers correspond to the message text in the
               ' message resource file defined for the source.
               Dim myInfoEvent As EventInstance = new EventInstance(InformationMsgId, 0, EventLogEntryType.Information)
               Dim myWarningEvent As EventInstance = new EventInstance(WarningMsgId, 0, EventLogEntryType.Warning)

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

               EventLog.WriteEvent(sourceName, myInfoEvent, insertStrings)

               ' Append binary data to the warning event entry.
               Dim binaryData() As Byte = { 7, 8, 9, 10 }
               EventLog.WriteEvent(sourceName, myWarningEvent, binaryData, insertStrings)
           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  
.  

설명

이 메서드를 사용하여 이벤트 로그에 대한 이벤트 원본으로 이미 등록된 원본을 사용하여 이벤트 로그에 추가 이벤트별 데이터가 있는 지역화된 항목을 작성합니다. 문자열 값이 아닌 리소스 식별자를 사용하여 이벤트 속성을 지정합니다. 이벤트 뷰어 리소스 식별자를 사용하여 원본에 대한 지역화된 리소스 파일의 해당 문자열을 표시합니다. 리소스 식별자를 사용하여 이벤트를 작성하기 전에 해당 리소스 파일에 원본을 등록해야 합니다.

입력 instance instance 이벤트 메시지 및 속성을 지정합니다. InstanceId 원본 메시지 리소스 파일에서 instance 정의된 메시지에 대한 입력의 를 설정합니다. 필요에 따라 입력의 instanceEntryTypeCategoryId 설정하여 이벤트 항목의 범주 및 이벤트 유형을 정의할 수 있습니다. 지역화된 메시지 텍스트에 삽입할 언어 독립적 문자열 배열을 지정할 수도 있습니다. null 이벤트 메시지에 대체 문자열에 대한 서식 지정 자리 표시자가 없는 경우 로 설정합니다values.

이벤트에 대한 추가 세부 정보를 제공해야 하는 경우 이벤트로 이진 데이터를 지정합니다. 예를 들어 매개 변수를 data 사용하여 특정 오류에 대한 정보를 포함합니다. 이벤트 뷰어 연결된 이벤트 데이터를 해석하지 않으며, 결합된 16진수 및 텍스트 형식으로 데이터를 표시합니다. 이벤트별 데이터를 드물게 사용합니다. 유용하다고 확신하는 경우에만 포함합니다. 또한 애플리케이션 이벤트 뷰어를 독립적으로 처리할 수 정보를 저장할 이벤트 관련 데이터를 사용할 수 있습니다. 예를 들어 이벤트에 대한 뷰어를 작성하거나 이벤트 로그를 검사하고 이벤트별 데이터의 정보를 포함하는 보고서를 만드는 프로그램을 작성할 수 있습니다.

를 사용하기 WriteEvent전에 지정된 원본을 이벤트 로그에 등록해야 합니다. 로그에 지역화된 항목을 작성하도록 지정된 원본을 구성해야 합니다. 원본에는 최소한 메시지 리소스 파일이 정의되어야 합니다.

원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다. 애플리케이션을 설치 하는 동안 새 이벤트 원본을 만듭니다. 이렇게 하면 운영 체제가 등록된 이벤트 원본 목록과 해당 구성을 새로 고칠 수 있습니다. 운영 체제에서 이벤트 소스 목록을 새로 고치지 않은 경우 쓰려고 하면 새 원본 사용 하는 이벤트는 쓰기 작업이 실패 합니다. 사용 하 여 새 소스를 구성할 수 있습니다는 EventLogInstaller를 사용 하 여 또는 CreateEventSource 메서드. 새 이벤트 원본을 만들려면 컴퓨터에서 관리자 권한이 있어야 합니다.

원본 또는 지역화 된 엔트리를 쓰기 위한 직접 문자열을 작성 하기 위한 구성 되어야 합니다. 사용 된 WriteEntry 메서드 애플리케이션 이벤트 로그에 직접 문자열 값을 기록 하는 경우.

애플리케이션 리소스 식별자와 문자열 값을 사용 하 여 항목을 기록 하는 경우 두 개의 별도 소스를 등록 해야 합니다. 예를 들어, 리소스 파일을 한 원본을 구성 하 고 해당 소스를 사용 하 여는 WriteEvent 메서드를 이벤트 로그에 리소스 식별자를 사용 하 여 항목을 씁니다. 그런 다음 리소스 파일 없이 다른 원본을 만들고 메서드에서 해당 원본을 WriteEntry 사용하여 해당 원본을 사용하여 이벤트 로그에 직접 문자열을 작성합니다.

추가 정보

적용 대상