EventSourceCreationData.Source Właściwość

Definicja

Pobiera lub ustawia nazwę, aby zarejestrować się w dzienniku zdarzeń jako źródło zdarzeń.

public:
 property System::String ^ Source { System::String ^ get(); void set(System::String ^ value); };
public string Source { get; set; }
member this.Source : string with get, set
Public Property Source As String

Wartość właściwości

Nazwa rejestrowania w dzienniku zdarzeń jako źródło wpisów. Wartością domyślną jest ciąg pusty ("").

Przykłady

Poniższy przykład kodu ustawia właściwości konfiguracji źródła zdarzeń z argumentów wiersza polecenia. Argumenty wejściowe określają nazwę źródła zdarzeń, nazwę dziennika zdarzeń, nazwę komputera i plik zasobu komunikatu o zdarzeniu. Ten przykład jest częścią większego przykładu udostępnionego EventSourceCreationData dla klasy.

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";
}
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";
}
         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

Uwagi

Nazwa źródła jest często nazwą aplikacji lub nazwą składnika w dużej aplikacji. Metoda EventLog.CreateEventSource(EventSourceCreationData) używa Sourcewłaściwości , LogNamei MachineName do tworzenia wartości rejestru na komputerze docelowym dla nowego źródła i skojarzonego z nim dziennika zdarzeń. Nowa nazwa źródła nie może być zgodna z istniejącą nazwą źródła lub istniejącą nazwą dziennika zdarzeń na komputerze docelowym.

Po utworzeniu wartości rejestru dla źródła aplikacja może użyć źródła do zapisywania wpisów w skonfigurowanym dzienniku zdarzeń.

Każde źródło może zapisywać tylko jeden dziennik zdarzeń jednocześnie; Jednak aplikacja może używać wielu źródeł do zapisywania w wielu dziennikach zdarzeń. Na przykład aplikacja może wymagać wielu źródeł skonfigurowanych dla różnych dzienników zdarzeń lub różnych plików zasobów.

Dotyczy

Zobacz też