EventLog.MachineName 속성

정의

이벤트를 읽거나 쓸 컴퓨터 이름을 가져오거나 설정합니다.

public:
 property System::String ^ MachineName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.SettingsBindable(true)]
public string MachineName { get; set; }
public string MachineName { get; set; }
[<System.ComponentModel.SettingsBindable(true)>]
member this.MachineName : string with get, set
member this.MachineName : string with get, set
Public Property MachineName As String

속성 값

이벤트 로그가 있는 서버의 이름입니다. 기본값은 로컬 컴퓨터(".")입니다.

특성

예외

컴퓨터 이름이 잘못된 경우

예제

다음 예제에서는 지정된 컴퓨터의 이벤트 로그 "NewEventLog"에 있는 항목을 읽습니다.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
int main()
{
   EventLog^ myNewLog = gcnew EventLog;
   myNewLog->Log = "NewEventLog";
   myNewLog->MachineName = "MyServer";
   System::Collections::IEnumerator^ myEnum = myNewLog->Entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
      Console::WriteLine( "\tEntry: {0}", entry->Message );
   }
}
using System;
using System.Diagnostics;

class MySample{

    public static void Main(){

        EventLog myNewLog = new EventLog();
        myNewLog.Log = "NewEventLog";
        myNewLog.MachineName = "MyServer";
        foreach(EventLogEntry entry in myNewLog.Entries){
            Console.WriteLine("\tEntry: " + entry.Message);
        }
    }
}
Imports System.Diagnostics

Class MySample
    Public Shared Sub Main()
        Dim myNewLog As New EventLog()
        myNewLog.Log = "NewEventLog"
        myNewLog.MachineName = "MyServer"
        Dim entry As EventLogEntry
        For Each entry In  myNewLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub
End Class

설명

이벤트 로그에 쓰는 경우 이벤트 로그 개체와 연결 Source 하여 특정 로그에 연결해야 합니다. 로그에서만 읽을 때 속성을 지정할 Source 필요는 없습니다. 이름 및 MachineName (서버 컴퓨터 이름)만 Log 지정할 수 있습니다.

참고

로그에 연결하는 경우 를 MachineName 지정할 필요가 없습니다. 를 지정 MachineName하지 않으면 로컬 컴퓨터(".")가 가정됩니다.

원본은 한 번에 하나의 로그에만 등록할 수 있습니다. 속성이 SourceEventLoginstance 대해 설정된 경우 값을 Source 변경하거나 먼저 를 호출 DeleteEventSource 하지 않고는 해당 EventLog 속성을 변경할 MachineName 수 없습니다. 속성을 변경 MachineName 하면 는 EventLog 모든 핸들을 닫고 새 컴퓨터의 로그 및 원본에 다시 연결합니다.

값은 MachineName 빈 문자열일 수 없습니다. 명시적으로 설정되지 않은 경우 기본값은 로컬 컴퓨터(".")입니다.

적용 대상

추가 정보