EventSourceCreationData 클래스

정의

로컬 컴퓨터 또는 원격 컴퓨터에서 이벤트 로그 소스를 만드는 데 사용되는 구성 설정을 나타냅니다.

public ref class EventSourceCreationData
public class EventSourceCreationData
type EventSourceCreationData = class
Public Class EventSourceCreationData
상속
EventSourceCreationData

예제

다음 코드 예제에서는 명령줄 인수에서 이벤트 원본에 대 한 구성 속성을 설정 합니다. 입력 인수는 이벤트 원본 이름, 이벤트 로그 이름, 컴퓨터 이름 및 이벤트 메시지 리소스 파일을 지정합니다. 코드 예제에서는 원본이 기존 이벤트 원본과 충돌하지 않는지 확인한 다음 지정된 이벤트 로그에 대한 새 이벤트 원본을 만듭니다.

#using <System.dll>

using namespace System;
using namespace System::Globalization;
using namespace System::Diagnostics;

[STAThread]
int main()
{
   array<String^>^args = Environment::GetCommandLineArgs();
   
   EventSourceCreationData ^ mySourceData = gcnew EventSourceCreationData( "","" );
   bool registerSource = true;
   
   // Process input parameters.
   if ( args->Length > 1 )
   {
      
      // Require at least the source name.
      mySourceData->Source = args[ 1 ];
      if ( args->Length > 2 )
      {
         mySourceData->LogName = args[ 2 ];
      }

      if ( args->Length > 3 )
      {
         mySourceData->MachineName = args[ 3 ];
      }

      if ( (args->Length > 4) && (args[ 4 ]->Length > 0) )
      {
         mySourceData->MessageResourceFile = args[ 4 ];
      }
   }
   else
   {
      
      // Display a syntax help message.
      Console::WriteLine( "Input:" );
      Console::WriteLine( " source [event log] [machine name] [resource file]" );
      registerSource = false;
   }

   
   // Set defaults for parameters missing input.
   if ( mySourceData->MachineName->Length == 0 )
   {
      
      // Default to the local computer.
      mySourceData->MachineName = ".";
   }

   if ( mySourceData->LogName->Length == 0 )
   {
      
      // Default to the Application log.
      mySourceData->LogName = "Application";
   }

   
   // Determine if the source exists on the specified computer.
   if (  !EventLog::SourceExists( mySourceData->Source, mySourceData->MachineName ) )
   {
      
      // The source does not exist.  
      // Verify that the message file exists
      // and the event log is local.
      if ( (mySourceData->MessageResourceFile != nullptr) && (mySourceData->MessageResourceFile->Length > 0) )
      {
         if ( mySourceData->MachineName->Equals( "." ) )
         {
            if (  !System::IO::File::Exists( mySourceData->MessageResourceFile ) )
            {
               Console::WriteLine( "File {0} not found - message file not set for source.", mySourceData->MessageResourceFile );
               registerSource = false;
            }
         }
         else
         {
            
            // For simplicity, do not allow setting the message
            // file for a remote event log.  To set the message
            // for a remote event log, and for source registration,
            // the file path should be specified with system-wide
            // environment variables that are valid on the remote
            // computer, such as
            // "%SystemRoot%\system32\myresource.dll".
            Console::WriteLine( "Message resource file ignored for remote event log." );
            registerSource = false;
         }
      }
   }
   else
   {
      
      // Do not register the source, it already exists.
      registerSource = false;
      
      // Get the event log corresponding to the existing source.
      String^ sourceLog;
      sourceLog = EventLog::LogNameFromSourceName( mySourceData->Source, mySourceData->MachineName );
      
      // Determine if the event source is registered for the 
      // specified log.
      if ( sourceLog->ToUpper( CultureInfo::InvariantCulture ) != mySourceData->LogName->ToUpper( CultureInfo::InvariantCulture ) )
      {
         
         // An existing source is registered 
         // to write to a different event log.
         Console::WriteLine( "Warning: source {0} is already registered to write to event log {1}", mySourceData->Source, sourceLog );
      }
      else
      {
         
         // The source is already registered 
         // to write to the specified event log.
         Console::WriteLine( "Source {0} already registered to write to event log {1}", mySourceData->Source, sourceLog );
      }
   }

   if ( registerSource )
   {
      
      // Register the new event source for the specified event log.
      Console::WriteLine( "Registering new source {0} for event log {1}.", mySourceData->Source, mySourceData->LogName );
      EventLog::CreateEventSource( mySourceData );
      Console::WriteLine( "Event source was registered successfully!" );
   }
}
using System;
using System.Globalization;
using System.Diagnostics;

namespace EventLogSamples
{
    class CreateSourceSample
    {
        [STAThread]
        static void Main(string[] args)
        {
            EventSourceCreationData mySourceData = new EventSourceCreationData("", "");
            bool registerSource = true;

            // Process input parameters.
            if (args.Length > 0)
            {
                // Require at least the source name.

                mySourceData.Source = args[0];

                if (args.Length > 1)
                {
                    mySourceData.LogName = args[1];
                }

                if (args.Length > 2)
                {
                    mySourceData.MachineName = args[2];
                }
                if ((args.Length > 3) && (args[3].Length > 0))
                {
                    mySourceData.MessageResourceFile = args[3];
                }
            }
            else
            {
                // Display a syntax help message.
                Console.WriteLine("Input:");
                Console.WriteLine(" source [event log] [machine name] [resource file]");

                registerSource = false;
            }

            // Set defaults for parameters missing input.
            if (mySourceData.MachineName.Length == 0)
            {
                // Default to the local computer.
                mySourceData.MachineName = ".";
            }
            if (mySourceData.LogName.Length == 0)
            {
                // Default to the Application log.
                mySourceData.LogName = "Application";
            }

            // Determine if the source exists on the specified computer.
            if (!EventLog.SourceExists(mySourceData.Source,
                                       mySourceData.MachineName))
            {
                // The source does not exist.

                // Verify that the message file exists
                // and the event log is local.

                if ((mySourceData.MessageResourceFile != null) &&
                    (mySourceData.MessageResourceFile.Length > 0))
                {
                    if (mySourceData.MachineName == ".")
                    {
                        if (!System.IO.File.Exists(mySourceData.MessageResourceFile))
                        {
                            Console.WriteLine("File {0} not found - message file not set for source.",
                                mySourceData.MessageResourceFile);
                            registerSource = false;
                        }
                    }
                    else
                    {
                        // For simplicity, do not allow setting the message
                        // file for a remote event log.  To set the message
                        // for a remote event log, and for source registration,
                        // the file path should be specified with system-wide
                        // environment variables that are valid on the remote
                        // computer, such as
                        // "%SystemRoot%\system32\myresource.dll".

                        Console.WriteLine("Message resource file ignored for remote event log.");
                        registerSource = false;
                    }
                }
            }
            else
            {
                // Do not register the source, it already exists.
                registerSource = false;

                // Get the event log corresponding to the existing source.
                string sourceLog;
                sourceLog = EventLog.LogNameFromSourceName(mySourceData.Source,
                                mySourceData.MachineName);

                // Determine if the event source is registered for the
                // specified log.

                if (sourceLog.ToUpper(CultureInfo.InvariantCulture) != mySourceData.LogName.ToUpper(CultureInfo.InvariantCulture))
                {
                    // An existing source is registered
                    // to write to a different event log.
                    Console.WriteLine("Warning: source {0} is already registered to write to event log {1}",
                        mySourceData.Source, sourceLog);
                }
                else
                {
                    // The source is already registered
                    // to write to the specified event log.

                    Console.WriteLine("Source {0} already registered to write to event log {1}",
                        mySourceData.Source, sourceLog);
                }
            }

            if (registerSource)
            {
                // Register the new event source for the specified event log.

                Console.WriteLine("Registering new source {0} for event log {1}.",
                    mySourceData.Source, mySourceData.LogName);
                EventLog.CreateEventSource(mySourceData);
                Console.WriteLine("Event source was registered successfully!");
            }
        }
    }
}
Imports System.Globalization
Imports System.Diagnostics

Namespace EventLogSamples
    Class CreateSourceSample

        Public Shared Sub Main(ByVal args() As String)
        
            Dim mySourceData As EventSourceCreationData = new EventSourceCreationData("", "")
            Dim registerSource As Boolean = True

            ' Process input parameters.
            If args.Length > 0
                ' Require at least the source name.

                mySourceData.Source = args(0)

                If args.Length > 1
   
                    mySourceData.LogName = args(1)
    
                End If
                If args.Length > 2
   
                    mySourceData.MachineName = args(2)
    
                End If
                If args.Length > 3 AndAlso args(3).Length > 0
   
                    mySourceData.MessageResourceFile = args(3)
    
                End If

            Else 
                ' Display a syntax help message.
                Console.WriteLine("Input:")
                Console.WriteLine(" source [event log] [machine name] [resource file]")

                registerSource = False
            End If

            ' Set defaults for parameters missing input.
            If mySourceData.MachineName.Length = 0
            
                ' Default to the local computer.
                mySourceData.MachineName = "."
            End If
            If mySourceData.LogName.Length = 0
                ' Default to the Application log.
                mySourceData.LogName = "Application"
            End If

            ' Determine if the source exists on the specified computer.
            If Not EventLog.SourceExists(mySourceData.Source, _
                                       mySourceData.MachineName)
                ' The source does not exist.  

                ' Verify that the message file exists
                ' and the event log is local.
                If mySourceData.MessageResourceFile <> Nothing AndAlso _
                   mySourceData.MessageResourceFile.Length > 0
                   
                    If mySourceData.MachineName = "."
                        If Not System.IO.File.Exists(mySourceData.MessageResourceFile)

                            Console.WriteLine("File {0} not found - message file not set for source.", _
                                mySourceData.MessageResourceFile)
                            registerSource = False
                        End If
                    Else
                        ' For simplicity, do not allow setting the message
                        ' file for a remote event log.  To set the message
                        ' for a remote event log, and for source registration,
                        ' the file path should be specified with system-wide
                        ' environment variables that are valid on the remote
                        ' computer, such as
                        ' "%SystemRoot%\system32\myresource.dll".

                        Console.WriteLine("Message resource file ignored for remote event log.")
                        registerSource = False

                    End If
                End If
            Else 
                ' Do not register the source, it already exists.
                registerSource = False

                ' Get the event log corresponding to the existing source.
                Dim sourceLog As string
                sourceLog = EventLog.LogNameFromSourceName(mySourceData.Source, _
                                mySourceData.MachineName)

                ' Determine if the event source is registered for the 
                ' specified log.

                If sourceLog.ToUpper(CultureInfo.InvariantCulture) <> mySourceData.LogName.ToUpper(CultureInfo.InvariantCulture)

                    ' An existing source is registered 
                    ' to write to a different event log.

                    Console.WriteLine("Warning: source {0} is already registered to write to event log {1}", _
                        mySourceData.Source, sourceLog)
                Else 
                    ' The source is already registered 
                    ' to write to the specified event log.

                    Console.WriteLine("Source {0} already registered to write to event log {1}", _
                        mySourceData.Source, sourceLog)

                End If
            End If

            If registerSource
                ' Register the new event source for the specified event log.

                Console.WriteLine("Registering new source {0} for event log {1}.", _
                    mySourceData.Source, mySourceData.LogName)
                EventLog.CreateEventSource(mySourceData)
                Console.WriteLine("Event source was registered successfully!")
            End If

        End Sub
    End Class
End Namespace 'EventLogSamples

설명

클래스를 EventSourceCreationData 사용하여 지역화된 항목을 이벤트 로그에 쓰기 위한 새 원본을 구성합니다. 이 클래스를 사용하여 이벤트 로그에서 읽을 필요는 없습니다.

이 클래스는 새 이벤트 원본 및 관련 이벤트 로그에 대한 구성 설정을 정의합니다. 연결된 이벤트 로그는 로컬 컴퓨터 또는 원격 컴퓨터에 있을 수 있습니다. 로컬 컴퓨터에서 새 이벤트 로그 또는 기존 이벤트 로그에 대한 새 원본을 만들려면 의 및 속성을 설정하고 LogName 메서드를 호출합니다EventLog.CreateEventSource(EventSourceCreationData).SourceEventSourceCreationData 이 메서드는 속성에 지정한 이벤트 원본을 Source 만들고 에 지정된 LogName이벤트 로그에 등록합니다. 이 동작은 클래스를 EventLogInstaller 사용하여 이벤트 로그에 대한 이벤트 원본을 등록하는 것과 비슷합니다.

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

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

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

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

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

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

원본 또는 지역화 된 엔트리를 쓰기 위한 직접 문자열을 작성 하기 위한 구성 되어야 합니다. 메서드는 WriteEntry 지정된 문자열을 이벤트 로그에 직접 씁니다. 지역화 가능한 메시지 리소스 파일을 사용하지 않습니다. 메서드를 WriteEvent 사용하여 지역화된 메시지 리소스 파일을 사용하여 이벤트를 작성합니다.

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

생성자

EventSourceCreationData(String, String)

지정된 이벤트 소스와 이벤트 로그 이름을 사용하여 EventSourceCreationData 클래스의 새 인스턴스를 초기화합니다.

속성

CategoryCount

범주 리소스 파일에서 범주 수를 가져오거나 설정합니다.

CategoryResourceFile

소스에 대한 범주 문자열이 들어 있는 리소스 파일의 경로를 가져오거나 설정합니다.

LogName

소스가 엔트리를 쓰는 이벤트 로그 이름을 가져오거나 설정합니다.

MachineName

이벤트 소스를 등록할 컴퓨터 이름을 가져오거나 설정합니다.

MessageResourceFile

소스에 대한 메시지 서식 문자열이 들어 있는 메시지 리소스 파일의 경로를 가져오거나 설정합니다.

ParameterResourceFile

소스에 대한 메시지 매개 변수 문자열이 들어 있는 리소스 파일의 경로를 가져오거나 설정합니다.

Source

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

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보