다음을 통해 공유


EventLog.CreateEventSource 메서드

정의

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

오버로드

CreateEventSource(EventSourceCreationData)

이벤트 원본 및 해당 이벤트 로그에 대해 지정된 구성 속성을 사용하여 지역화된 이벤트 메시지를 작성하기 위한 유효한 이벤트 원본을 설정합니다.

CreateEventSource(String, String)

로컬 컴퓨터의 로그에 항목을 쓰기 위한 유효한 이벤트 원본으로 지정된 소스 이름을 설정합니다. 이 메서드는 로컬 컴퓨터에 새 사용자 지정 로그를 만들 수도 있습니다.

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

지정된 원본 이름을 지정된 컴퓨터의 로그에 항목을 쓰기 위한 유효한 이벤트 원본으로 설정합니다. 이 메서드를 사용하여 지정된 컴퓨터에 새 사용자 지정 로그를 만들 수도 있습니다.

CreateEventSource(EventSourceCreationData)

Source:
EventLog.cs
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 이벤트 원본이 로컬 컴퓨터에 등록되어 있는지 여부를 확인합니다. 이벤트 원본이 없으면 원본에 대한 메시지 리소스 파일을 설정하고 새 이벤트 원본을 만드는 예제입니다. 마지막으로 DisplayNameMsgId 리소스 식별자 값과 messageFile리소스 파일 경로를 사용하여 이벤트 로그의 지역화된 표시 이름을 설정합니다.

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(사용자 계정 컨트롤)는 사용자의 권한을 결정합니다. 기본 제공 관리자 그룹의 구성원인 경우 표준 사용자 액세스 토큰과 관리자 액세스 토큰이라는 두 개의 런타임 액세스 토큰이 할당됩니다. 기본적으로 표준 사용자 역할에 있습니다. 보안 로그에 액세스하는 코드를 실행하려면 먼저 표준 사용자에서 관리자로 권한을 상승시켜야 합니다. 애플리케이션 아이콘을 마우스 오른쪽 단추로 클릭하고 관리자 권한으로 실행하려는 경우 애플리케이션을 시작할 때 이 작업을 수행할 수 있습니다.

WriteEventWriteEntry 사용하여 이벤트 로그에 이벤트를 씁니다. 이벤트를 작성하려면 이벤트 원본을 지정해야 합니다. 원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다.

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

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

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

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

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

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

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

메모

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

추가 정보

적용 대상

CreateEventSource(String, String)

Source:
EventLog.cs
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(사용자 계정 컨트롤)는 사용자의 권한을 결정합니다. 기본 제공 관리자 그룹의 구성원인 경우 표준 사용자 액세스 토큰과 관리자 액세스 토큰이라는 두 개의 런타임 액세스 토큰이 할당됩니다. 기본적으로 표준 사용자 역할에 있습니다. 보안 로그에 액세스하는 코드를 실행하려면 먼저 표준 사용자에서 관리자로 권한을 상승시켜야 합니다. 애플리케이션 아이콘을 마우스 오른쪽 단추로 클릭하고 관리자 권한으로 실행하려는 경우 애플리케이션을 시작할 때 이 작업을 수행할 수 있습니다.

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

메모

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

WriteEventWriteEntry 사용하여 이벤트 로그에 이벤트를 씁니다. 이벤트를 작성하려면 이벤트 원본을 지정해야 합니다. 원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다.

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

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

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

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

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

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

메모

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

추가 정보

적용 대상

CreateEventSource(String, String, String)

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

주의

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

주의

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

지정된 원본 이름을 지정된 컴퓨터의 로그에 항목을 쓰기 위한 유효한 이벤트 원본으로 설정합니다. 이 메서드를 사용하여 지정된 컴퓨터에 새 사용자 지정 로그를 만들 수도 있습니다.

public:
 static void CreateEventSource(System::String ^ source, System::String ^ logName, System::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")]
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.")>]
static member CreateEventSource : string * string * string -> unit
static member CreateEventSource : string * string * string -> unit
[<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
Public Shared Sub CreateEventSource (source As String, logName As String, machineName As String)

매개 변수

source
String

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

logName
String

원본의 항목이 기록되는 로그의 이름입니다. 가능한 값에는 애플리케이션, 시스템 또는 사용자 지정 이벤트 로그가 포함됩니다. 값을 지정하지 않으면 logName 기본값이 Application으로 설정됩니다.

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 사용하여 항목을 배치할 적절한 로그를 찾습니다. 이벤트 로그를 읽는 경우 Source지정하거나 Log 지정하고 MachineName수 있습니다.

메모

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

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

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

WriteEventWriteEntry 사용하여 이벤트 로그에 이벤트를 씁니다. 이벤트를 작성하려면 이벤트 원본을 지정해야 합니다. 원본을 사용하여 첫 번째 항목을 작성하기 전에 이벤트 원본을 만들고 구성해야 합니다.

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

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

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

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

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

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

메모

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

추가 정보

적용 대상