EventLog.Source 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
이벤트 로그에 쓸 때 등록하고 사용할 원본 이름을 가져오거나 설정합니다.
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;
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 항목을 배치할 적절한 로그를 찾습니다. 이벤트 로그를 읽는 경우 , 또는 a Log 및 MachineName를 지정할 Source수 있습니다.
메모
로컬 컴퓨터의 MachineName 로그에 연결하는 경우 지정할 필요가 없습니다. 지정 MachineName하지 않으면 로컬 컴퓨터(".")가 가정됩니다.
WriteEntry 이벤트 로그에 이벤트를 사용하고 WriteEvent 씁니다. 이벤트를 작성하려면 이벤트 원본을 지정해야 합니다. 원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다.
애플리케이션을 설치하는 동안 새 이벤트 원본을 만듭니다. 이렇게 하면 운영 체제에서 등록된 이벤트 원본 목록과 해당 구성을 새로 고칠 수 있습니다. 운영 체제에서 이벤트 원본 목록을 새로 고치지 않고 새 원본으로 이벤트를 작성하려고 하면 쓰기 작업이 실패합니다. 또는 메서드를 사용하여 새 원본을 EventLogInstallerCreateEventSource 구성할 수 있습니다. 새 이벤트 원본을 만들려면 컴퓨터에 대한 관리 권한이 있어야 합니다.
기존 이벤트 로그 또는 새 이벤트 로그에 대한 이벤트 원본을 만들 수 있습니다. 새 이벤트 로그에 대한 새 원본을 만들면 시스템에서 해당 로그의 원본을 등록하지만 첫 번째 항목이 기록될 때까지 로그가 만들어지지 않습니다.
원본은 로컬 컴퓨터에서 고유해야 합니다. 새 원본 이름은 기존 원본 이름 또는 기존 이벤트 로그 이름과 일치할 수 없습니다. 각 원본은 한 번에 하나의 이벤트 로그에만 쓸 수 있습니다. 그러나 애플리케이션은 여러 원본을 사용하여 여러 이벤트 로그에 쓸 수 있습니다. 예를 들어 애플리케이션에는 여러 이벤트 로그 또는 다른 리소스 파일에 대해 구성된 여러 원본이 필요할 수 있습니다.
값을 변경 Source 하면 등록된 값 EventLog 이 닫히고 모든 이벤트 핸들이 해제됩니다.
지역화된 항목을 작성하거나 직접 문자열을 작성하기 위해 원본을 구성해야 합니다. 애플리케이션에서 리소스 식별자와 문자열 값을 모두 사용하여 항목을 작성하는 경우 두 개의 개별 소스를 등록해야 합니다. 예를 들어 리소스 파일을 사용하여 하나의 원본을 구성한 다음 메서드에서 WriteEvent 해당 원본을 사용하여 이벤트 로그에 리소스 식별자를 사용하여 항목을 작성합니다. 그런 다음 리소스 파일 없이 다른 원본을 만들고 메서드에서 WriteEntry 해당 원본을 사용하여 해당 원본을 사용하여 이벤트 로그에 직접 문자열을 작성합니다.
기존 원본의 구성 세부 정보를 변경하려면 원본을 삭제한 다음 새 구성을 사용하여 만들어야 합니다. 다른 애플리케이션 또는 구성 요소에서 기존 원본을 사용하는 경우 기존 원본을 삭제하는 대신 업데이트된 구성으로 새 원본을 만듭니다.
메모
원본이 이미 로그에 매핑되어 새 로그에 다시 매핑된 경우 변경 내용을 적용하려면 컴퓨터를 다시 시작해야 합니다.