EventLog.SourceExists 메서드

정의

컴퓨터 레지스트리에서 지정한 이벤트 소스를 검색합니다.

오버로드

SourceExists(String)

이벤트 소스가 로컬 컴퓨터에 등록되었는지를 확인합니다.

SourceExists(String, String)

이벤트 소스가 지정한 컴퓨터에 등록되었는지를 확인합니다.

SourceExists(String)

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

이벤트 소스가 로컬 컴퓨터에 등록되었는지를 확인합니다.

public:
 static bool SourceExists(System::String ^ source);
public static bool SourceExists (string source);
static member SourceExists : string -> bool
Public Shared Function SourceExists (source As String) As Boolean

매개 변수

source
String

이벤트 원본의 이름입니다.

반환

로컬 컴퓨터에 이벤트 소스가 등록되어 있으면 true이고, 그렇지 않으면 false입니다.

예외

source를 찾을 수 없었지만 모든 또는 일부 이벤트 로그를 검색할 수 없는 경우

예제

다음 예제에서는 소스가 없는 경우 를 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" ) )
   {
      EventLog::CreateEventSource( "MySource", "MyNewLog" );
      Console::WriteLine( "CreatingEventSource" );
   }

   
   // 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." );
   Console::WriteLine( "Message written 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("CreatingEventSource");
            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.");

        Console.WriteLine("Message written to event log.");
    }
}
Option Explicit
Option Strict
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        ' Create the source, if it does not already exist.
        If Not EventLog.SourceExists("MySource") Then
            EventLog.CreateEventSource("MySource", "MyNewLog")
            Console.WriteLine("CreatingEventSource")
        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.")
        
        Console.WriteLine("Message written to event log.")
    End Sub
End Class

설명

이 메서드를 사용하여 이벤트 원본이 로컬 컴퓨터에 있는지 여부를 확인합니다. 로컬 컴퓨터에 로그가 있는지 여부를 확인하려면 를 사용합니다 Exists.

이 메서드는 레지스트리에 액세스하므로 로컬 컴퓨터에 적절한 레지스트리 권한이 있어야 합니다. 그렇지 않으면 가 SecurityException throw됩니다.

참고

Windows Vista 이상 또는 Windows Server 2003에서 이벤트 원본을 검색하려면 관리 권한이 있어야 합니다.

이 요구 사항의 이유는 보안을 포함한 모든 이벤트 로그를 검색하여 이벤트 원본이 고유한지 여부를 확인해야 하기 때문입니다. Windows Vista부터 사용자는 보안 로그에 액세스할 수 있는 권한이 없습니다. 따라서 가 SecurityException throw됩니다.

Windows Vista부터 UAC(사용자 계정 컨트롤)는 사용자의 권한을 결정합니다. 기본 제공 Administrators 그룹의 멤버인 경우 두 개의 런타임 액세스 토큰(표준 사용자 액세스 토큰 및 관리자 액세스 토큰)이 할당됩니다. 기본적으로 표준 사용자 역할이 지정됩니다. 성능 카운터에 액세스하는 코드를 실행하려면 먼저 표준 사용자에서 관리자로 권한을 상승시켜야 합니다. 애플리케이션 아이콘을 마우스 오른쪽 단추로 클릭하고 관리자로 실행하도록 지정하여 애플리케이션을 시작하면 이 작업을 수행할 수 있습니다.

참고

계정에서 LocalSystem 실행되는 서비스에는 이 메서드를 실행하는 데 필요한 권한이 없습니다. 솔루션은 이벤트 원본이 에 ServiceInstaller있는지 여부를 검사 설치 관리자에 원본을 만드는 것입니다.

새 원본에 동일한 컴퓨터의 기존 원본 이름을 지정할 수 없으므로 를 호출 CreateEventSource 하기 전에 이 메서드를 사용하여 로 지정된 source 이름의 원본이 로컬 컴퓨터에 아직 없는지 확인합니다. 매개 변수는 source 대/소문자를 구분하지 않습니다.

추가 정보

적용 대상

SourceExists(String, String)

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

이벤트 소스가 지정한 컴퓨터에 등록되었는지를 확인합니다.

public:
 static bool SourceExists(System::String ^ source, System::String ^ machineName);
public static bool SourceExists (string source, string machineName);
static member SourceExists : string * string -> bool
Public Shared Function SourceExists (source As String, machineName As String) As Boolean

매개 변수

source
String

이벤트 원본의 이름입니다.

machineName
String

검색할 컴퓨터의 이름입니다. 로컬 컴퓨터의 경우에는 "."입니다.

반환

지정한 컴퓨터에 이벤트 원본이 등록되어 있으면 true이고, 등록되지 않았으면 false입니다.

예외

machineName이 잘못된 컴퓨터 이름인 경우

source를 찾을 수 없었지만 모든 또는 일부 이벤트 로그를 검색할 수 없는 경우

예제

다음 예제에서는 컴퓨터에 MyServer원본 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", "MyServer" ) )
   {
      EventLog::CreateEventSource( "MySource", "MyNewLog", "MyServer" );
      Console::WriteLine( "CreatingEventSource" );
   }

   
   // 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." );
   Console::WriteLine( "Message written 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", "MyServer"))
        {
            // 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");
            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.");

        Console.WriteLine("Message written to event log.");
    }
}
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        ' Create the source, if it does not already exist.
        If Not EventLog.SourceExists("MySource", "MyServer") Then
            EventLog.CreateEventSource("MySource", "MyNewLog", "MyServer")
            Console.WriteLine("CreatingEventSource")
        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.")
        
        Console.WriteLine("Message written to event log.")
    End Sub
End Class

설명

이 메서드를 사용하여 매개 변수로 지정된 machineName 컴퓨터에 이벤트 원본이 있는지 여부를 확인합니다. 지정된 컴퓨터에 로그가 있는지 여부를 확인하려면 을 사용합니다 Exists.

이 메서드는 레지스트리에 액세스하므로 지정된 서버에 대한 적절한 레지스트리 권한이 있어야 합니다. 그렇지 않으면 가 SecurityException throw됩니다.

참고

Windows Vista 이상 또는 Windows Server 2003에서 이벤트 원본을 검색하려면 관리 권한이 있어야 합니다.

이 요구 사항의 이유는 보안을 포함한 모든 이벤트 로그를 검색하여 이벤트 원본이 고유한지 여부를 확인해야 하기 때문입니다. Windows Vista부터 사용자는 보안 로그에 액세스할 수 있는 권한이 없습니다. 따라서 가 SecurityException throw됩니다.

Windows Vista부터 UAC(사용자 계정 컨트롤)는 사용자의 권한을 결정합니다. 기본 제공 Administrators 그룹의 멤버인 경우 두 개의 런타임 액세스 토큰(표준 사용자 액세스 토큰 및 관리자 액세스 토큰)이 할당됩니다. 기본적으로 표준 사용자 역할이 지정됩니다. 성능 카운터에 액세스하는 코드를 실행하려면 먼저 표준 사용자에서 관리자로 권한을 상승시켜야 합니다. 애플리케이션 아이콘을 마우스 오른쪽 단추로 클릭하고 관리자로 실행하도록 지정하여 애플리케이션을 시작하면 이 작업을 수행할 수 있습니다.

참고

계정에서 LocalSystem 실행되는 서비스에는 이 메서드를 실행하는 데 필요한 권한이 없습니다. 솔루션은 이벤트 원본이 에 ServiceInstaller있는지 여부를 검사 설치 관리자에 원본을 만드는 것입니다.

새 원본에 동일한 컴퓨터의 기존 원본 이름을 지정할 수 없으므로 를 호출 CreateEventSource 하기 전에 이 메서드를 사용하여 에 지정된 source 이름의 원본이 컴퓨터에 아직 없는지 확인합니다. sourcemachineName 매개 변수는 대/소문자를 구분하지 않습니다.

SourceExistsstatic 메서드이므로 클래스 자체에서 호출할 수 있습니다. 를 호출SourceExists하는 의 instance EventLog 만들 필요는 없습니다.

추가 정보

적용 대상