EventLog.CreateEventSource 메서드

정의

시스템의 특정 로그에 이벤트 정보를 쓸 수 있도록 애플리케이션을 설정합니다.

오버로드

CreateEventSource(EventSourceCreationData)

이벤트 소스와 해당 이벤트 로그에 대한 지정된 구성 속성을 사용하여 지역화된 이벤트 메시지를 작성할 올바른 이벤트 소스를 설정합니다.

CreateEventSource(String, String)

로컬 컴퓨터의 로그에 엔트리를 쓰는 유효한 이벤트 소스로 지정된 소스 이름을 설정합니다. 또한 이 방법을 사용하면 로컬 컴퓨터에 새로운 사용자 지정 로그를 만들 수도 있습니다.

CreateEventSource(String, String, String)
사용되지 않음.
사용되지 않음.
사용되지 않음.

지정된 컴퓨터의 로그에 엔트리를 쓰는 유효한 이벤트 소스로 지정된 소스 이름을 설정합니다. 또한 이 방법을 사용하면 지정한 컴퓨터에 새로운 사용자 지정 로그를 만들 수도 있습니다.

CreateEventSource(EventSourceCreationData)

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

이벤트 소스와 해당 이벤트 로그에 대한 지정된 구성 속성을 사용하여 지역화된 이벤트 메시지를 작성할 올바른 이벤트 소스를 설정합니다.

public:
 static void CreateEventSource(System::Diagnostics::EventSourceCreationData ^ sourceData);
public static void CreateEventSource (System.Diagnostics.EventSourceCreationData sourceData);
static member CreateEventSource : System.Diagnostics.EventSourceCreationData -> unit
Public Shared Sub CreateEventSource (sourceData As EventSourceCreationData)

매개 변수

sourceData
EventSourceCreationData

이벤트 원본과 대상 이벤트 로그에 대한 구성 속성입니다.

예외

sourceData에 지정한 컴퓨터 이름이 잘못된 경우

또는

sourceData에 지정된 소스 이름이 null인 경우

또는

sourceData에 지정한 로그 이름이 잘못된 경우. 이벤트 로그 이름은 인쇄 가능한 문자로 구성되어야 하며 '*', '?', '\' 문자를 포함할 수 없습니다.

또는

sourceData에 지정한 로그 이름을 사용자 로그를 만드는 데 사용할 수 없는 경우. 이벤트 로그 이름 AppEvent, SysEvent 및 SecEvent는 시스템용으로 예약되어 있습니다.

또는

로그 이름이 기존 이벤트 소스 이름과 일치하는 경우

또는

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

또는

sourceData에 지정한 로그 이름의 처음 8개 문자가 고유하지 않은 경우

또는

sourceData에 지정한 소스 이름이 이미 등록된 경우

또는

sourceData에 지정한 소스 이름이 기존 이벤트 로그 이름과 일치하는 경우

이벤트 로그의 레지스트리 키를 열 수 없는 경우

sourceData이(가) null인 경우

예제

다음 예제에서는 라는 SampleApplicationSource 이벤트 원본이 로컬 컴퓨터에 등록되어 있는지 여부를 확인합니다. 이벤트 원본이 없는 경우 예제에서는 원본에 대한 메시지 리소스 파일을 설정하고 새 이벤트 원본을 만듭니다. 마지막으로, 예제에서는 의 리소스 식별자 값과 의 리소스 파일 경로를 messageFile사용하여 이벤트 로그에 DisplayNameMsgId 대한 지역화된 표시 이름을 설정합니다.

void CreateEventSourceSample1( String^ messageFile )
{
   String^ myLogName;
   String^ sourceName = "SampleApplicationSource";
   
   // Create the event source if it does not exist.
   if (  !EventLog::SourceExists( sourceName ) )
   {
      
      // Create a new event source for the custom event log
      // named "myNewLog."  
      myLogName = "myNewLog";
      EventSourceCreationData ^ mySourceData = gcnew EventSourceCreationData( sourceName,myLogName );
      
      // Set the message resource file that the event source references.
      // All event resource identifiers correspond to text in this file.
      if (  !System::IO::File::Exists( messageFile ) )
      {
         Console::WriteLine( "Input message resource file does not exist - {0}", messageFile );
         messageFile = "";
      }
      else
      {
         
         // Set the specified file as the resource
         // file for message text, category text, and 
         // message parameter strings.  
         mySourceData->MessageResourceFile = messageFile;
         mySourceData->CategoryResourceFile = messageFile;
         mySourceData->CategoryCount = CategoryCount;
         mySourceData->ParameterResourceFile = messageFile;
         Console::WriteLine( "Event source message resource file set to {0}", messageFile );
      }

      Console::WriteLine( "Registering new source for event log." );
      EventLog::CreateEventSource( mySourceData );
   }
   else
   {
      
      // Get the event log corresponding to the existing source.
      myLogName = EventLog::LogNameFromSourceName( sourceName, "." );
   }

   
   // Register the localized name of the event log.
   // For example, the actual name of the event log is "myNewLog," but
   // the event log name displayed in the Event Viewer might be
   // "Sample Application Log" or some other application-specific
   // text.
   EventLog^ myEventLog = gcnew EventLog( myLogName,".",sourceName );
   if ( messageFile->Length > 0 )
   {
      myEventLog->RegisterDisplayName( messageFile, DisplayNameMsgId );
   }   
}
static void CreateEventSourceSample1(string messageFile)
{
    string myLogName;
    string sourceName = "SampleApplicationSource";

    // Create the event source if it does not exist.
    if(!EventLog.SourceExists(sourceName))
    {
        // Create a new event source for the custom event log
        // named "myNewLog."

        myLogName = "myNewLog";
        EventSourceCreationData mySourceData = new EventSourceCreationData(sourceName, myLogName);

        // Set the message resource file that the event source references.
        // All event resource identifiers correspond to text in this file.
        if (!System.IO.File.Exists(messageFile))
        {
            Console.WriteLine("Input message resource file does not exist - {0}",
                messageFile);
            messageFile = "";
        }
        else
        {
            // Set the specified file as the resource
            // file for message text, category text, and
            // message parameter strings.

            mySourceData.MessageResourceFile = messageFile;
            mySourceData.CategoryResourceFile = messageFile;
            mySourceData.CategoryCount = CategoryCount;
            mySourceData.ParameterResourceFile = messageFile;

            Console.WriteLine("Event source message resource file set to {0}",
                messageFile);
        }

        Console.WriteLine("Registering new source for event log.");
        EventLog.CreateEventSource(mySourceData);
    }
    else
    {
        // Get the event log corresponding to the existing source.
        myLogName = EventLog.LogNameFromSourceName(sourceName,".");
    }

    // Register the localized name of the event log.
    // For example, the actual name of the event log is "myNewLog," but
    // the event log name displayed in the Event Viewer might be
    // "Sample Application Log" or some other application-specific
    // text.
    EventLog myEventLog = new EventLog(myLogName, ".", sourceName);

    if (messageFile.Length > 0)
    {
        myEventLog.RegisterDisplayName(messageFile, DisplayNameMsgId);
    }
}
Public Shared Sub CreateEventSourceSample1(ByVal messageFile As String)

    Dim myLogName As String
    Dim sourceName As String = "SampleApplicationSource"

    ' Create the event source if it does not exist.
    If Not EventLog.SourceExists(sourceName)
    
        ' Create a new event source for the custom event log
        ' named "myNewLog."  

        myLogName = "myNewLog"
        Dim mySourceData As EventSourceCreationData = New EventSourceCreationData(sourceName, myLogName)

        ' Set the message resource file that the event source references.
        ' All event resource identifiers correspond to text in this file.
        If Not System.IO.File.Exists(messageFile)

            Console.WriteLine("Input message resource file does not exist - {0}", _
                messageFile)
            messageFile = ""
        Else 
            ' Set the specified file as the resource
            ' file for message text, category text and 
            ' message parameters strings.

            mySourceData.MessageResourceFile = messageFile
            mySourceData.CategoryResourceFile = messageFile
            mySourceData.CategoryCount = CategoryCount
            mySourceData.ParameterResourceFile = messageFile

            Console.WriteLine("Event source message resource file set to {0}", _
                messageFile)
        End If

        Console.WriteLine("Registering new source for event log.")
        EventLog.CreateEventSource(mySourceData)
    Else
        ' Get the event log corresponding to the existing source.
        myLogName = EventLog.LogNameFromSourceName(sourceName,".")
    End If

    ' Register the localized name of the event log.
    ' For example, the actual name of the event log is "myNewLog," but
    ' the event log name displayed in the Event Viewer might be
    ' "Sample Application Log" or some other application-specific
    ' text.
    Dim myEventLog As EventLog = New EventLog(myLogName, ".", sourceName)
    
    If messageFile.Length > 0
        myEventLog.RegisterDisplayName(messageFile, DisplayNameMsgId)
    End If
End Sub

이 예제에서는 리소스 라이브러리 EventLogMsgs.dll 기본 제공되는 다음 메시지 텍스트 파일을 사용합니다. 메시지 텍스트 파일은 메시지 리소스 파일 생성 되는 원본. 메시지 텍스트 파일의 리소스 식별자와 범주, 이벤트 메시지 및 매개 변수 삽입 문자열에 대 한 텍스트를 정의합니다. 특히 리소스 식별자 5001은 이벤트 로그의 지역화된 이름에 대해 정의됩니다.

; // EventLogMsgs.mc  
; // ********************************************************  

; // Use the following commands to build this file:  

; //   mc -s EventLogMsgs.mc  
; //   rc EventLogMsgs.rc  
; //   link /DLL /SUBSYSTEM:WINDOWS /NOENTRY /MACHINE:x86 EventLogMsgs.Res   
; // ********************************************************  

; // - Event categories -  
; // Categories must be numbered consecutively starting at 1.  
; // ********************************************************  

MessageId=0x1  
Severity=Success  
SymbolicName=INSTALL_CATEGORY  
Language=English  
Installation  
.  

MessageId=0x2  
Severity=Success  
SymbolicName=QUERY_CATEGORY  
Language=English  
Database Query  
.  

MessageId=0x3  
Severity=Success  
SymbolicName=REFRESH_CATEGORY  
Language=English  
Data Refresh  
.  

; // - Event messages -  
; // *********************************  

MessageId = 1000  
Severity = Success  
Facility = Application  
SymbolicName = AUDIT_SUCCESS_MESSAGE_ID_1000  
Language=English  
My application message text, in English, for message id 1000, called from %1.  
.  

MessageId = 1001  
Severity = Warning  
Facility = Application  
SymbolicName = AUDIT_FAILED_MESSAGE_ID_1001  
Language=English  
My application message text, in English, for message id 1001, called from %1.  
.  

MessageId = 1002  
Severity = Success  
Facility = Application  
SymbolicName = GENERIC_INFO_MESSAGE_ID_1002  
Language=English  
My generic information message in English, for message id 1002.  
.  

MessageId = 1003  
Severity = Warning  
Facility = Application  
SymbolicName = GENERIC_WARNING_MESSAGE_ID_1003  
Language=English  
My generic warning message in English, for message id 1003, called from %1.  
.  

MessageId = 1004  
Severity = Success  
Facility = Application  
SymbolicName = UPDATE_CYCLE_COMPLETE_MESSAGE_ID_1004  
Language=English  
The update cycle is complete for %%5002.  
.  

MessageId = 1005  
Severity = Warning  
Facility = Application  
SymbolicName = SERVER_CONNECTION_DOWN_MESSAGE_ID_1005  
Language=English  
The refresh operation did not complete because the connection to server %1 could not be established.  
.  

; // - Event log display name -  
; // ********************************************************  

MessageId = 5001  
Severity = Success  
Facility = Application  
SymbolicName = EVENT_LOG_DISPLAY_NAME_MSGID  
Language=English  
Sample Event Log  
.  

; // - Event message parameters -  
; //   Language independent insertion strings  
; // ********************************************************  

MessageId = 5002  
Severity = Success  
Facility = Application  
SymbolicName = EVENT_LOG_SERVICE_NAME_MSGID  
Language=English  
SVC_UPDATE.EXE  
.  

설명

이 오버로드를 사용하여 로컬 컴퓨터 또는 원격 컴퓨터의 이벤트 로그에 항목을 쓰기 위한 새 원본을 구성합니다. 이벤트 로그에서 읽는 데 이 메서드를 사용할 필요는 없습니다.

메서드는 CreateEventSource 입력 sourceDataSource, LogNameMachineName 속성을 사용하여 대상 컴퓨터에서 새 원본 및 관련 이벤트 로그에 대한 레지스트리 값을 만듭니다. 새 원본 이름은 대상 컴퓨터의 기존 원본 이름 또는 기존 이벤트 로그 이름과 일치할 수 없습니다. 경우는 LogName 속성이 설정 되지 않은, 애플리케이션 이벤트 로그에 대 한 소스가 등록 합니다. 이 MachineName 설정되지 않으면 원본이 로컬 컴퓨터에 등록됩니다.

참고

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

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

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

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

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

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

이벤트 로그는 운영 체제에 파일로 저장됩니다. 또는 CreateEventSource 를 사용하여 EventLogInstaller 새 이벤트 로그를 만들면 연결된 파일이 지정된 컴퓨터의 %SystemRoot%\System32\Config 디렉터리에 저장됩니다. 파일 이름은의 처음 8 개 문자를 추가 하 여 설정 됩니다는 Log ".evt" 파일 이름 확장명을 가진 속성입니다.

각 소스에서는 한 번에 하나의 이벤트 로그에 쓸 수 있습니다만 그러나 애플리케이션이 여러 이벤트 로그에 쓸 여러 원본을 사용할 수 있습니다. 예를 들어, 애플리케이션에 다른 이벤트 로그 또는 다른 리소스 파일에 대해 구성 된 여러 소스가 필요할 수 있습니다.

이벤트 범주 및 메시지 문자열에 대해 지역화된 리소스 파일에 이벤트 원본을 등록할 수 있습니다. 애플리케이션 실제 문자열을 지정 하는 대신 리소스 식별자를 사용 하 여 이벤트 로그 엔트리를 쓸 수 있습니다. 이벤트 뷰어를 찾아 현재 언어 설정에 따라 지역화 된 리소스 파일에서 해당 문자열을 표시할 리소스 식별자를 사용 합니다. 이벤트 범주, 메시지 및 매개 변수 삽입 문자열에 대해 별도의 파일을 등록하거나 세 가지 유형의 문자열 모두에 대해 동일한 리소스 파일을 등록할 수 있습니다. 사용 합니다 CategoryCount, CategoryResourceFileMessageResourceFile, 및 ParameterResourceFile 이벤트 로그에 지역화 된 엔트리를 쓸 원본을 구성 하는 속성입니다. 애플리케이션 이벤트 로그에 직접 문자열 값을 쓰는, 경우에 이러한 속성을 설정할 필요가 없습니다.

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

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

참고

원본이 이벤트 로그에 대해 구성되고 다른 이벤트 로그에 대해 다시 구성한 경우 변경 내용을 적용하려면 컴퓨터를 다시 시작해야 합니다.

추가 정보

적용 대상

CreateEventSource(String, String)

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

로컬 컴퓨터의 로그에 엔트리를 쓰는 유효한 이벤트 소스로 지정된 소스 이름을 설정합니다. 또한 이 방법을 사용하면 로컬 컴퓨터에 새로운 사용자 지정 로그를 만들 수도 있습니다.

public:
 static void CreateEventSource(System::String ^ source, System::String ^ logName);
public static void CreateEventSource (string source, string logName);
static member CreateEventSource : string * string -> unit
Public Shared Sub CreateEventSource (source As String, logName As String)

매개 변수

source
String

로컬 컴퓨터에 등록되는 애플리케이션의 원본 이름입니다.

logName
String

소스 엔트리를 쓸 로그의 이름입니다. 가능한 값은 애플리케이션, 시스템 또는 사용자 지정 이벤트 로그를 포함합니다.

예외

source가 빈 문자열("")이나 null인 경우

또는

logName이 올바른 이벤트 로그 이름이 아닌 경우. 이벤트 로그 이름은 인쇄 가능한 문자로 구성되어야 하며 '*', '?', '\' 문자를 포함할 수 없습니다.

또는

logName은 사용자 로그 작성에 유효하지 않습니다. 이벤트 로그 이름 AppEvent, SysEvent 및 SecEvent는 시스템용으로 예약되어 있습니다.

또는

로그 이름이 기존 이벤트 소스 이름과 일치하는 경우

또는

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

또는

logName의 처음 8개 문자가 기존 이벤트 로그 이름의 처음 8개 문자와 일치하는 경우

또는

소스가 이미 로컬 컴퓨터에 있기 때문에 해당 소스를 등록할 수 없는 경우

또는

소스 이름이 기존 이벤트 로그 이름과 일치하는 경우

이벤트 로그의 레지스트리 키를 로컬 컴퓨터에서 열 수 없는 경우

예제

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

설명

이 오버로드를 사용하여 사용자 지정 로그를 만들거나 를 만들고 로컬 컴퓨터의 기존 로그에 등록 Source 합니다.

경우 logName 됩니다 null 이거나 빈 문자열 ("") 호출 하는 경우 CreateEventSource, 애플리케이션 로그에 기본적으로 로그. 로그는 로컬 컴퓨터에 없는 경우 시스템 사용자 지정 로그를 만들고 애플리케이션으로 등록을 Source 해당 로그에 대 한 합니다.

참고

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

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

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

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

참고

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

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

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

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

이벤트 로그는 운영 체제에 파일로 저장됩니다. 또는 CreateEventSource 를 사용하여 EventLogInstaller 새 이벤트 로그를 만들면 연결된 파일이 지정된 컴퓨터의 %SystemRoot%\System32\Config 디렉터리에 저장됩니다. 파일 이름은의 처음 8 개 문자를 추가 하 여 설정 됩니다는 Log ".evt" 파일 이름 확장명을 가진 속성입니다.

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

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

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

참고

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

추가 정보

적용 대상

CreateEventSource(String, String, String)

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

주의

This method has been deprecated. Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead. http://go.microsoft.com/fwlink/?linkid=14202

주의

This method has been deprecated. Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead. https://go.microsoft.com/fwlink/?linkid=14202

주의

EventLog.CreateEventSource has been deprecated. Use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.

지정된 컴퓨터의 로그에 엔트리를 쓰는 유효한 이벤트 소스로 지정된 소스 이름을 설정합니다. 또한 이 방법을 사용하면 지정한 컴퓨터에 새로운 사용자 지정 로그를 만들 수도 있습니다.

public:
 static void CreateEventSource(System::String ^ source, System::String ^ logName, System::String ^ machineName);
[System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.  http://go.microsoft.com/fwlink/?linkid=14202")]
public static void CreateEventSource (string source, string logName, string machineName);
[System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.  https://go.microsoft.com/fwlink/?linkid=14202")]
public static void CreateEventSource (string source, string logName, string machineName);
[System.Obsolete("EventLog.CreateEventSource has been deprecated. Use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.")]
public static void CreateEventSource (string source, string logName, string machineName);
public static void CreateEventSource (string source, string logName, string machineName);
[<System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.  http://go.microsoft.com/fwlink/?linkid=14202")>]
static member CreateEventSource : string * string * string -> unit
[<System.Obsolete("This method has been deprecated.  Please use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.  https://go.microsoft.com/fwlink/?linkid=14202")>]
static member CreateEventSource : string * string * string -> unit
[<System.Obsolete("EventLog.CreateEventSource has been deprecated. Use System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData) instead.")>]
static member CreateEventSource : string * string * string -> unit
static member CreateEventSource : string * string * string -> unit
Public Shared Sub CreateEventSource (source As String, logName As String, machineName As String)

매개 변수

source
String

지정한 컴퓨터에 등록되는 애플리케이션의 원본입니다.

logName
String

소스 엔트리를 쓸 로그의 이름입니다. 가능한 값은 애플리케이션, 시스템 또는 사용자 지정 이벤트 로그를 포함합니다. 값을 지정하지 않은 경우 기본적으로 logName은 애플리케이션이 됩니다.

machineName
String

이 이벤트 원본을 등록할 컴퓨터의 이름입니다. 로컬 컴퓨터의 경우에는 "."입니다.

특성

예외

machineName이 올바른 컴퓨터 이름이 아닌 경우

또는

source가 빈 문자열("")이나 null인 경우

또는

logName이 올바른 이벤트 로그 이름이 아닌 경우. 이벤트 로그 이름은 인쇄 가능한 문자로 구성되어야 하며 '*', '?', '\' 문자를 포함할 수 없습니다.

또는

logName은 사용자 로그 작성에 유효하지 않습니다. 이벤트 로그 이름 AppEvent, SysEvent 및 SecEvent는 시스템용으로 예약되어 있습니다.

또는

로그 이름이 기존 이벤트 소스 이름과 일치하는 경우

또는

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

또는

logName의 처음 8개 문자가 지정된 컴퓨터에 있는 기존 이벤트 로그 이름의 처음 8개 문자와 일치하는 경우

또는

소스가 이미 지정한 컴퓨터에 있기 때문에 해당 소스를 등록할 수 없는 경우

또는

소스 이름이 기존 이벤트 소스 이름과 일치하는 경우

이벤트 로그의 레지스트리 키를 지정한 컴퓨터에서 열 수 없는 경우

예제

다음 예제에서는 컴퓨터에 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

설명

이 오버로드를 사용하여 사용자 지정 로그를 만들거나 지정된 컴퓨터의 기존 로그를 만들고 등록 Source 할 수 있습니다.

경우 logName 됩니다 null 이거나 빈 문자열 ("") 호출 하는 경우 CreateEventSource, 애플리케이션 로그에 기본적으로 로그. 지정한 컴퓨터의 로그 없으면 시스템 사용자 지정 로그를 만들고 애플리케이션으로 등록을 Source 해당 로그에 대 한 합니다.

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

참고

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

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

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

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

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

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

이벤트 로그는 운영 체제에 파일로 저장됩니다. 또는 CreateEventSource 를 사용하여 EventLogInstaller 새 이벤트 로그를 만들면 연결된 파일이 지정된 컴퓨터의 %SystemRoot%\System32\Config 디렉터리에 저장됩니다. 파일 이름은의 처음 8 개 문자를 추가 하 여 설정 됩니다는 Log ".evt" 파일 이름 확장명을 가진 속성입니다.

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

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

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

참고

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

추가 정보

적용 대상