EventLog 생성자

정의

EventLog 클래스의 새 인스턴스를 초기화합니다.

오버로드

EventLog()

EventLog 클래스의 새 인스턴스를 초기화합니다. 인스턴스를 로그와 연결하지 않습니다.

EventLog(String)

EventLog 클래스의 새 인스턴스를 초기화합니다. 로컬 컴퓨터에 있는 로그에 인스턴스를 연결합니다.

EventLog(String, String)

EventLog 클래스의 새 인스턴스를 초기화합니다. 지정한 컴퓨터에 있는 로그에 인스턴스를 연결합니다.

EventLog(String, String, String)

EventLog 클래스의 새 인스턴스를 초기화합니다. 지정한 컴퓨터에 있는 로그에 인스턴스를 연결하고 EventLog에 지정한 원본을 만들거나 할당합니다.

EventLog()

Source:
EventLog.cs
Source:
EventLog.cs
Source:
EventLog.cs

EventLog 클래스의 새 인스턴스를 초기화합니다. 인스턴스를 로그와 연결하지 않습니다.

public:
 EventLog();
public EventLog ();
Public Sub New ()

예제

다음 예제에서는 소스가 없는 경우 를 MySource 만들고 이벤트 로그 MyNewLog에 항목을 씁니다.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   
   // Create the source, if it does not already exist.
   if (  !EventLog::SourceExists( "MySource" ) )
   {
      //An event log source should not be created and immediately used.
      //There is a latency time to enable the source, it should be created
      //prior to executing the application that uses the source.
      //Execute this sample a second time to use the new source.
      EventLog::CreateEventSource( "MySource", "MyNewLog" );
      Console::WriteLine( "CreatingEventSource" );
      // The source is created.  Exit the application to allow it to be registered.
      return 0;
   }

   
   // Create an EventLog instance and assign its source.
   EventLog^ myLog = gcnew EventLog;
   myLog->Source = "MySource";
   
   // Write an informational entry to the event log.    
   myLog->WriteEntry( "Writing to event log." );
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample{

    public static void Main(){

        // Create the source, if it does not already exist.
        if(!EventLog.SourceExists("MySource"))
        {
             //An event log source should not be created and immediately used.
             //There is a latency time to enable the source, it should be created
             //prior to executing the application that uses the source.
             //Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog");
            Console.WriteLine("CreatedEventSource");
            Console.WriteLine("Exiting, execute the application a second time to use the source.");
            // The source is created.  Exit the application to allow it to be registered.
            return;
        }

        // Create an EventLog instance and assign its source.
        EventLog myLog = new EventLog();
        myLog.Source = "MySource";

        // Write an informational entry to the event log.
        myLog.WriteEntry("Writing to event log.");
    }
}
Option Explicit
Option Strict

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        
        If Not EventLog.SourceExists("MySource") Then
            ' Create the source, if it does not already exist.
            ' An event log source should not be created and immediately used.
            ' There is a latency time to enable the source, it should be created
            ' prior to executing the application that uses the source.
            ' Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog")
            Console.WriteLine("CreatingEventSource")
            'The source is created.  Exit the application to allow it to be registered.
            Return
        End If
        
        ' Create an EventLog instance and assign its source.
        Dim myLog As New EventLog()
        myLog.Source = "MySource"
        
        ' Write an informational entry to the event log.    
        myLog.WriteEntry("Writing to event log.")
    End Sub
End Class

설명

를 호출WriteEntry하기 전에 instance 속성을 EventLog 지정 Source 합니다. 로그에서만 읽 Entries 는 경우 및 MachineName 속성만 Log 지정할 수 있습니다.

참고

를 지정 MachineName하지 않으면 로컬 컴퓨터(".")가 가정됩니다.

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. EventLog합니다.

속성 초기 값
Source 빈 문자열("")입니다.
Log 빈 문자열("")입니다.
MachineName 로컬 컴퓨터(".").

추가 정보

적용 대상

EventLog(String)

Source:
EventLog.cs
Source:
EventLog.cs
Source:
EventLog.cs

EventLog 클래스의 새 인스턴스를 초기화합니다. 로컬 컴퓨터에 있는 로그에 인스턴스를 연결합니다.

public:
 EventLog(System::String ^ logName);
public EventLog (string logName);
new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog
Public Sub New (logName As String)

매개 변수

logName
String

로컬 컴퓨터의 로그 이름입니다.

예외

로그 이름이 null인 경우

로그 이름이 잘못된 경우

예제

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

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
    // Create the source, if it does not already exist.
   if (  !EventLog::SourceExists( "MySource" ) )
   {
      //An event log source should not be created and immediately used.
      //There is a latency time to enable the source, it should be created
      //prior to executing the application that uses the source.
      //Execute this sample a second time to use the new source.
      EventLog::CreateEventSource( "MySource", "MyNewLog" );
      Console::WriteLine( "CreatingEventSource" );
      // The source is created.  Exit the application to allow it to be registered.
      return 0;
   }

   
   // Create an EventLog instance and assign its log name.
   EventLog^ myLog = gcnew EventLog( "myNewLog" );
   
   // Read the event log entries.
   System::Collections::IEnumerator^ myEnum = myLog->Entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
      Console::WriteLine( "\tEntry: {0}", entry->Message );
   }
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample
{
    public static void Main()
    {
        // Create the source, if it does not already exist.
        if (!EventLog.SourceExists("MySource"))
        {
            //An event log source should not be created and immediately used.
            //There is a latency time to enable the source, it should be created
            //prior to executing the application that uses the source.
            //Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog");
            Console.WriteLine("CreatedEventSource");
            Console.WriteLine("Exiting, execute the application a second time to use the source.");
            // The source is created.  Exit the application to allow it to be registered.
            return;
        }

        // Create an EventLog instance and assign its log name.
        EventLog myLog = new EventLog("myNewLog");

        // Read the event log entries.
        foreach (EventLogEntry entry in myLog.Entries)
        {
            Console.WriteLine("\tEntry: " + entry.Message);
        }
    }
}
Option Explicit
Option Strict

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        
        If Not EventLog.SourceExists("MySource") Then
            ' Create the source, if it does not already exist.
            ' An event log source should not be created and immediately used.
            ' There is a latency time to enable the source, it should be created
            ' prior to executing the application that uses the source.
            ' Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog")
            Console.WriteLine("CreatingEventSource")
            'The source is created.  Exit the application to allow it to be registered.
            Return
        End If

        Dim myLog As New EventLog("myNewLog")
        
        ' Read the event log entries.
        Dim entry As EventLogEntry
        For Each entry In  myLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub
End Class

설명

이 오버 로드는 Log 속성을 매개 변수로 logName 설정합니다. 를 호출WriteEntry하기 전에 instance 속성을 EventLog 지정 Source 합니다. 로그에서만 읽 Entries 는 경우 및 MachineName 속성만 Log 지정할 수 있습니다.

참고

를 지정 MachineName하지 않으면 로컬 컴퓨터(".")가 가정됩니다. 생성자의 이 오버로드는 속성을 지정 Log 하지만 속성을 읽기 Entries 전에 변경할 수 있습니다.

속성에 Source 지정한 원본이 컴퓨터의 다른 원본과 고유한 경우 다음에 를 호출하면 WriteEntry 지정된 이름의 로그가 생성됩니다(아직 없는 경우).

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. EventLog합니다.

속성 초기 값
Source 빈 문자열("")입니다.
Log logName 매개 변수입니다.
MachineName 로컬 컴퓨터(".").

추가 정보

적용 대상

EventLog(String, String)

Source:
EventLog.cs
Source:
EventLog.cs
Source:
EventLog.cs

EventLog 클래스의 새 인스턴스를 초기화합니다. 지정한 컴퓨터에 있는 로그에 인스턴스를 연결합니다.

public:
 EventLog(System::String ^ logName, System::String ^ machineName);
public EventLog (string logName, string machineName);
new System.Diagnostics.EventLog : string * string -> System.Diagnostics.EventLog
Public Sub New (logName As String, machineName As String)

매개 변수

logName
String

지정된 컴퓨터의 로그 이름입니다.

machineName
String

로그가 있는 컴퓨터입니다.

예외

로그 이름이 null인 경우

로그 이름이 잘못된 경우

또는

컴퓨터 이름이 잘못된 경우

예제

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

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   // Create the source, if it does not already exist.
   if (  !EventLog::SourceExists( "MySource" ) )
   {
      //An event log source should not be created and immediately used.
      //There is a latency time to enable the source, it should be created
      //prior to executing the application that uses the source.
      //Execute this sample a second time to use the new source.
      EventLog::CreateEventSource( "MySource", "MyNewLog", "myServer" );
      Console::WriteLine( "CreatingEventSource" );
      // The source is created.  Exit the application to allow it to be registered.
      return 0;
   }

   // Create an EventLog instance and assign its log name.
   EventLog^ myLog = gcnew EventLog( "myNewLog","myServer" );
   
   // Read the event log entries.
   System::Collections::IEnumerator^ myEnum = myLog->Entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
      Console::WriteLine( "\tEntry: {0}", entry->Message );
   }
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample1
{
    public static void Main()
    {
        // Create the source, if it does not already exist.
        if (!EventLog.SourceExists("MySource"))
        {
            //An event log source should not be created and immediately used.
            //There is a latency time to enable the source, it should be created
            //prior to executing the application that uses the source.
            //Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog", "myServer");
            Console.WriteLine("CreatedEventSource");
            Console.WriteLine("Exiting, execute the application a second time to use the source.");
            // The source is created.  Exit the application to allow it to be registered.
            return;
        }
        // Create an EventLog instance and assign its log name.
        EventLog myLog = new EventLog("myNewLog", "myServer");

        // Read the event log entries.
        foreach (EventLogEntry entry in myLog.Entries)
        {
            Console.WriteLine("\tEntry: " + entry.Message);
        }
    }
}
Option Explicit
Option Strict

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        If Not EventLog.SourceExists("MySource") Then
            ' Create the source, if it does not already exist.
            ' An event log source should not be created and immediately used.
            ' There is a latency time to enable the source, it should be created
            ' prior to executing the application that uses the source.
            ' Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog", "myServer")
            Console.WriteLine("CreatingEventSource")
            'The source is created.  Exit the application to allow it to be registered.
            Return
        End If

        ' Create an EventLog instance and assign its log name.
        Dim myLog As New EventLog("myNewLog", "myServer")
        
        ' Read the event log entries.
        Dim entry As EventLogEntry
        For Each entry In  myLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub
End Class

설명

이 오버로드는 속성을 매개 변수로 logName 설정하고 속성을 매개 MachineName 변수로 machineName 설정합니다Log. 를 호출 WriteEntry하기 전에 의 Source 속성을 지정합니다 EventLog. 로그에서만 읽 Entries 는 경우 및 MachineName 속성만 Log 지정할 수 있습니다.

참고

생성자의 이 오버로드는 및 MachineName 속성을 지정 Log 하지만 속성을 읽기 Entries 전에 변경할 수 있습니다.

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. EventLog합니다.

속성 초기 값
Source 빈 문자열("")입니다.
Log logName 매개 변수입니다.
MachineName machineName 매개 변수입니다.

추가 정보

적용 대상

EventLog(String, String, String)

Source:
EventLog.cs
Source:
EventLog.cs
Source:
EventLog.cs

EventLog 클래스의 새 인스턴스를 초기화합니다. 지정한 컴퓨터에 있는 로그에 인스턴스를 연결하고 EventLog에 지정한 원본을 만들거나 할당합니다.

public:
 EventLog(System::String ^ logName, System::String ^ machineName, System::String ^ source);
public EventLog (string logName, string machineName, string source);
new System.Diagnostics.EventLog : string * string * string -> System.Diagnostics.EventLog
Public Sub New (logName As String, machineName As String, source As String)

매개 변수

logName
String

지정된 컴퓨터의 로그 이름입니다.

machineName
String

로그가 있는 컴퓨터입니다.

source
String

이벤트 로그 항목의 원본입니다.

예외

로그 이름이 null인 경우

로그 이름이 잘못된 경우

또는

컴퓨터 이름이 잘못된 경우

예제

다음 예제에서는 원본 "MySource"를 사용하여 로컬 컴퓨터의 이벤트 로그 "MyNewLog"에 항목을 씁니다.

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   // Create the source, if it does not already exist.
   if (  !EventLog::SourceExists( "MySource" ) )
   {
      //An event log source should not be created and immediately used.
      //There is a latency time to enable the source, it should be created
      //prior to executing the application that uses the source.
      //Execute this sample a second time to use the new source.
      EventLog::CreateEventSource( "MySource", "MyNewLog");
      Console::WriteLine( "CreatingEventSource" );
      // The source is created.  Exit the application to allow it to be registered.
      return 0;
   }
   
   // Create an EventLog instance and assign its source.
   EventLog^ myLog = gcnew EventLog( "myNewLog",".","MySource" );
   
   // Write an entry to the log.        
   myLog->WriteEntry( String::Format( "Writing to event log on {0}", myLog->MachineName ) );
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample2
{
    public static void Main()
    {
        // Create the source, if it does not already exist.
        if (!EventLog.SourceExists("MySource"))
        {
            //An event log source should not be created and immediately used.
            //There is a latency time to enable the source, it should be created
            //prior to executing the application that uses the source.
            //Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog");
            Console.WriteLine("CreatedEventSource");
            Console.WriteLine("Exiting, execute the application a second time to use the source.");
            // The source is created.  Exit the application to allow it to be registered.
            return;
        }
        // Create an EventLog instance and assign its source.
        EventLog myLog = new EventLog("myNewLog", ".", "MySource");

        // Write an entry to the log.
        myLog.WriteEntry("Writing to event log on " + myLog.MachineName);
    }
}
Option Strict
Option Explicit

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        If Not EventLog.SourceExists("MySource") Then
            ' Create the source, if it does not already exist.
            ' An event log source should not be created and immediately used.
            ' There is a latency time to enable the source, it should be created
            ' prior to executing the application that uses the source.
            ' Execute this sample a second time to use the new source.
            EventLog.CreateEventSource("MySource", "MyNewLog")
            Console.WriteLine("CreatingEventSource")
            'The source is created.  Exit the application to allow it to be registered.
            Return
        End If
        ' Create an EventLog instance and assign its source.
        Dim myLog As New EventLog("myNewLog", ".", "MySource")
        
        ' Write an entry to the log.        
        myLog.WriteEntry(("Writing to event log on " & myLog.MachineName))
    End Sub
End Class

설명

이 생성자는 속성을 매개 변수로logName, MachineName 속성을 매개 변수로machineName, Source 속성을 매개 변수로 source 설정합니다Log. 속성은 Source 이벤트 로그에 쓸 때 필요합니다. 그러나 이벤트 로그에서만 읽는 경우 서버의 Log 이벤트 로그에 이미 연결된 원본이 있는 한 및 MachineName 속성만 필요합니다. 이벤트 로그에서만 읽는 경우 생성자의 또 다른 오버로드로 충분할 수 있습니다.

다음 표에서 인스턴스에 대 한 초기 속성 값을 보여 줍니다. EventLog합니다.

속성 초기 값
Source source 매개 변수입니다.
Log logName 매개 변수입니다.
MachineName machineName 매개 변수입니다.

추가 정보

적용 대상