EventLog Konstruktoren

Definition

Initialisiert eine neue Instanz der EventLog-Klasse.

Überlädt

EventLog()

Initialisiert eine neue Instanz der EventLog-Klasse. Die Instanz wird keinem Protokoll zugeordnet.

EventLog(String)

Initialisiert eine neue Instanz der EventLog-Klasse. Ordnet die Instanz einem Protokoll auf dem lokalen Computer zu.

EventLog(String, String)

Initialisiert eine neue Instanz der EventLog-Klasse. Ordnet die Instanz einem Protokoll auf dem angegebenen Computer zu.

EventLog(String, String, String)

Initialisiert eine neue Instanz der EventLog-Klasse. Ordnet die Instanz einem Protokoll auf dem angegebenen Computer zu und erstellt die angegebene Quelle bzw. weist diese dem EventLog zu.

EventLog()

Quelle:
EventLog.cs
Quelle:
EventLog.cs
Quelle:
EventLog.cs

Initialisiert eine neue Instanz der EventLog-Klasse. Die Instanz wird keinem Protokoll zugeordnet.

public:
 EventLog();
public EventLog ();
Public Sub New ()

Beispiele

Im folgenden Beispiel wird die Quelle MySource erstellt, sofern sie noch nicht vorhanden ist, und schreibt einen Eintrag in das Ereignisprotokoll 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

Hinweise

Geben Sie vor dem Aufrufen WriteEntrydie Source -Eigenschaft des EventLog instance an. Wenn Sie nur aus dem Protokoll lesen Entries , können Sie alternativ nur die Log Eigenschaften und MachineName angeben.

Hinweis

Wenn Sie kein angeben MachineName, wird der lokale Computer (".") angenommen.

Die folgende Tabelle zeigt die anfänglichen Eigenschaftswerte für eine instance von EventLog.

Eigenschaft Anfangswert
Source Eine leere Zeichenfolge ("").
Log Eine leere Zeichenfolge ("").
MachineName Der lokale Computer (".").

Weitere Informationen

Gilt für:

EventLog(String)

Quelle:
EventLog.cs
Quelle:
EventLog.cs
Quelle:
EventLog.cs

Initialisiert eine neue Instanz der EventLog-Klasse. Ordnet die Instanz einem Protokoll auf dem lokalen Computer zu.

public:
 EventLog(System::String ^ logName);
public EventLog (string logName);
new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog
Public Sub New (logName As String)

Parameter

logName
String

Der Name des Protokolls auf dem lokalen Computer.

Ausnahmen

Der Protokollname ist null.

Der Protokollname ist ungültig.

Beispiele

Im folgenden Beispiel werden Einträge im Ereignisprotokoll "myNewLog" auf dem lokalen Computer gelesen.

#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 log name.
   EventLog^ myLog = gcnew EventLog( "myNewLog" );
   
   // Read the event log entries.
   System::Collections::IEnumerator^ myEnum = myLog->Entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
      Console::WriteLine( "\tEntry: {0}", entry->Message );
   }
}
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 log name.
        EventLog myLog = new EventLog("myNewLog");

        // Read the event log entries.
        foreach (EventLogEntry entry in myLog.Entries)
        {
            Console.WriteLine("\tEntry: " + entry.Message);
        }
    }
}
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

        Dim myLog As New EventLog("myNewLog")
        
        ' Read the event log entries.
        Dim entry As EventLogEntry
        For Each entry In  myLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub
End Class

Hinweise

Diese Überladung legt die Log -Eigenschaft auf den logName -Parameter fest. Geben Sie vor dem Aufrufen WriteEntrydie Source -Eigenschaft des EventLog instance an. Wenn Sie nur aus dem Protokoll lesen Entries , können Sie alternativ nur die Log Eigenschaften und MachineName angeben.

Hinweis

Wenn Sie kein angeben MachineName, wird der lokale Computer (".") angenommen. Diese Überladung des Konstruktors gibt die Log -Eigenschaft an, aber Sie können dies ändern, bevor Sie die Entries Eigenschaft lesen.

Wenn die Quelle, die Sie in der Source -Eigenschaft angeben, von anderen Quellen auf dem Computer eindeutig ist, wird bei einem nachfolgenden Aufruf WriteEntry von ein Protokoll mit dem angegebenen Namen erstellt, sofern es noch nicht vorhanden ist.

Die folgende Tabelle zeigt die anfänglichen Eigenschaftswerte für eine instance von EventLog.

Eigenschaft Anfangswert
Source Eine leere Zeichenfolge ("").
Log Der logName-Parameter.
MachineName Der lokale Computer (".").

Weitere Informationen

Gilt für:

EventLog(String, String)

Quelle:
EventLog.cs
Quelle:
EventLog.cs
Quelle:
EventLog.cs

Initialisiert eine neue Instanz der EventLog-Klasse. Ordnet die Instanz einem Protokoll auf dem angegebenen Computer zu.

public:
 EventLog(System::String ^ logName, System::String ^ machineName);
public EventLog (string logName, string machineName);
new System.Diagnostics.EventLog : string * string -> System.Diagnostics.EventLog
Public Sub New (logName As String, machineName As String)

Parameter

logName
String

Der Name des Protokolls auf dem angegebenen Computer.

machineName
String

Der Computer, auf dem das Protokoll vorhanden ist.

Ausnahmen

Der Protokollname ist null.

Der Protokollname ist ungültig.

- oder -

Der Computername ist ungültig.

Beispiele

Im folgenden Beispiel werden Einträge im Ereignisprotokoll "myNewLog" auf dem Computer "myServer" gelesen.

#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", "myServer" );
      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 log name.
   EventLog^ myLog = gcnew EventLog( "myNewLog","myServer" );
   
   // Read the event log entries.
   System::Collections::IEnumerator^ myEnum = myLog->Entries->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      EventLogEntry^ entry = safe_cast<EventLogEntry^>(myEnum->Current);
      Console::WriteLine( "\tEntry: {0}", entry->Message );
   }
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample1
{
    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", "myServer");
            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 log name.
        EventLog myLog = new EventLog("myNewLog", "myServer");

        // Read the event log entries.
        foreach (EventLogEntry entry in myLog.Entries)
        {
            Console.WriteLine("\tEntry: " + entry.Message);
        }
    }
}
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", "myServer")
            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 log name.
        Dim myLog As New EventLog("myNewLog", "myServer")
        
        ' Read the event log entries.
        Dim entry As EventLogEntry
        For Each entry In  myLog.Entries
            Console.WriteLine((ControlChars.Tab & "Entry: " & entry.Message))
        Next entry
    End Sub
End Class

Hinweise

Diese Überladung legt die Log -Eigenschaft auf den logName -Parameter und die MachineName -Eigenschaft auf den machineName -Parameter fest. Geben Sie vor dem Aufrufen WriteEntryder -Eigenschaft die Source -Eigenschaft von an EventLog. Wenn Sie nur aus dem Protokoll lesen Entries , können Sie alternativ nur die Log Eigenschaften und MachineName angeben.

Hinweis

Diese Überladung des Konstruktors gibt die Log Eigenschaften und MachineName an, sie können jedoch vor dem Lesen der Entries Eigenschaft geändert werden.

Die folgende Tabelle zeigt die anfänglichen Eigenschaftswerte für eine instance von EventLog.

Eigenschaft Anfangswert
Source Eine leere Zeichenfolge ("").
Log Der logName-Parameter.
MachineName Der machineName-Parameter.

Weitere Informationen

Gilt für:

EventLog(String, String, String)

Quelle:
EventLog.cs
Quelle:
EventLog.cs
Quelle:
EventLog.cs

Initialisiert eine neue Instanz der EventLog-Klasse. Ordnet die Instanz einem Protokoll auf dem angegebenen Computer zu und erstellt die angegebene Quelle bzw. weist diese dem EventLog zu.

public:
 EventLog(System::String ^ logName, System::String ^ machineName, System::String ^ source);
public EventLog (string logName, string machineName, string source);
new System.Diagnostics.EventLog : string * string * string -> System.Diagnostics.EventLog
Public Sub New (logName As String, machineName As String, source As String)

Parameter

logName
String

Der Name des Protokolls auf dem angegebenen Computer.

machineName
String

Der Computer, auf dem das Protokoll vorhanden ist.

source
String

Die Quelle für Ereignisprotokolleinträge.

Ausnahmen

Der Protokollname ist null.

Der Protokollname ist ungültig.

- oder -

Der Computername ist ungültig.

Beispiele

Im folgenden Beispiel wird ein Eintrag in das Ereignisprotokoll "MyNewLog" auf dem lokalen Computer geschrieben, wobei die Quelle "MySource" verwendet wird.

#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( "myNewLog",".","MySource" );
   
   // Write an entry to the log.        
   myLog->WriteEntry( String::Format( "Writing to event log on {0}", myLog->MachineName ) );
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample2
{
    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("myNewLog", ".", "MySource");

        // Write an entry to the log.
        myLog.WriteEntry("Writing to event log on " + myLog.MachineName);
    }
}
Option Strict
Option Explicit

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("myNewLog", ".", "MySource")
        
        ' Write an entry to the log.        
        myLog.WriteEntry(("Writing to event log on " & myLog.MachineName))
    End Sub
End Class

Hinweise

Dieser Konstruktor legt die Log -Eigenschaft auf den logName -Parameter, die MachineName -Eigenschaft auf den machineName -Parameter und die Source -Eigenschaft auf den source -Parameter fest. Die Source -Eigenschaft ist beim Schreiben in ein Ereignisprotokoll erforderlich. Wenn Sie jedoch nur aus einem Ereignisprotokoll lesen, sind nur die Log Eigenschaften und MachineName erforderlich (sofern dem Ereignisprotokoll auf dem Server bereits eine Quelle zugeordnet ist). Wenn Sie nur aus dem Ereignisprotokoll lesen, kann eine andere Überladung des Konstruktors ausreichen.

Die folgende Tabelle zeigt die anfänglichen Eigenschaftswerte für eine instance von EventLog.

Eigenschaft Anfangswert
Source Der source-Parameter.
Log Der logName-Parameter.
MachineName Der machineName-Parameter.

Weitere Informationen

Gilt für: