EventLog.Source 속성

정의

이벤트 로그에 쓸 때 등록하고 사용할 소스 이름을 가져오거나 설정합니다.

public:
 property System::String ^ Source { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.SettingsBindable(true)]
public string Source { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Source { get; set; }
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Source { get; set; }
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string Source { get; set; }
[<System.ComponentModel.SettingsBindable(true)>]
member this.Source : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Source : string with get, set
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Source : string with get, set
[<System.ComponentModel.SettingsBindable(true)>]
[<System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.Source : string with get, set
Public Property Source As String

속성 값

엔트리 소스로 이벤트 로그에 등록되는 이름입니다. 기본값은 빈 문자열("")입니다.

특성

예외

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

예제

다음 예제에서는 소스가 아직 없는 경우 를 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

설명

이벤트 원본을 이벤트 로그를 나타냅니다. 것이 애플리케이션의 이름 또는 애플리케이션의 하위 구성의 이름을 애플리케이션이 큰 경우. 애플리케이션 및 서비스 애플리케이션 로그 나 사용자 지정 로그에 작성 해야 합니다. 디바이스 드라이버는 시스템 로그에 작성 해야 합니다.

이벤트 로그에 쓰는 경우에만 이벤트 원본을 지정하면 됩니다. 이벤트 로그에 항목을 작성하기 전에 이벤트 로그에 이벤트 원본을 유효한 이벤트 원본으로 등록해야 합니다. 로그 항목을 작성할 때 시스템은 속성을 사용하여 Source 항목을 배치할 적절한 로그를 찾습니다. 이벤트 로그를 읽는 경우 , 또는 및 MachineNameSourceLog 지정할 수 있습니다.

참고

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

WriteEntry 를 사용하여 WriteEvent 이벤트 로그에 이벤트를 씁니다. 이벤트를 작성 하는 이벤트 원본을 지정 해야 합니다. 만들기 및 소스를 사용 하 여 첫 번째 항목을 작성 하기 전에 이벤트 소스를 구성 해야 합니다.

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

기존 이벤트 로그 또는 새 이벤트 로그의 이벤트 소스를 만들 수 있습니다. 새 이벤트 로그에 대 한 새 소스를 만들면 해당 로그에 대 한 소스를 등록 하는 시스템 있지만 첫 번째 항목에 기록할 때 까지는 로그가 만들어지지 않습니다.

원본은 로컬 컴퓨터에서 고유해야 합니다. 새 원본 이름은 기존 원본 이름 또는 기존 이벤트 로그 이름과 일치할 수 없습니다. 각 소스에서는 한 번에 하나의 이벤트 로그에 쓸 수 있습니다. 그러나 애플리케이션이 여러 이벤트 로그에 쓸 여러 원본을 사용할 수 있습니다. 예를 들어, 애플리케이션에 다른 이벤트 로그 또는 다른 리소스 파일에 대해 구성 된 여러 소스가 필요할 수 있습니다.

값을 EventLog 변경 Source 하면 등록된 가 닫혀 모든 이벤트 핸들이 해제됩니다.

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

기존 원본의 구성 세부 정보를 변경하려면 원본을 삭제한 다음 새 구성으로 만들어야 합니다. 다른 애플리케이션이 나 구성 요소는 기존 소스를 사용 하는 경우 기존 소스를 삭제 하는 대신 업데이트 된 구성을 사용 하 여 새 소스를 만듭니다.

참고

원본이 이미 로그에 매핑되어 새 로그에 다시 매핑된 경우 변경 내용을 적용하려면 컴퓨터를 다시 시작해야 합니다.

적용 대상

추가 정보