Questo articolo è stato tradotto automaticamente. Per visualizzare l'articolo in inglese, selezionare la casella di controllo Inglese. È possibile anche visualizzare il testo inglese in una finestra popup posizionando il puntatore del mouse sopra il testo.
Traduzione
Inglese

Costruttore EventLog ()

 

Data di pubblicazione: novembre 2016

Inizializza una nuova istanza della classe EventLog. Non associa l'istanza ad alcun log.

Spazio dei nomi:   System.Diagnostics
Assembly:  System (in System.dll)

public EventLog()

Before calling Overload:System.Diagnostics.EventLog.WriteEntry, specify the P:System.Diagnostics.EventLog.Source property of the T:System.Diagnostics.EventLog instance. If you are only reading P:System.Diagnostics.EventLog.Entries from the log, you can alternatively specify only the P:System.Diagnostics.EventLog.Log and P:System.Diagnostics.EventLog.MachineName properties.

System_CAPS_noteNota

If you do not specify a P:System.Diagnostics.EventLog.MachineName, the local computer (".") is assumed.

The following table shows initial property values for an instance of T:System.Diagnostics.EventLog.

Property

Initial Value

Source

An empty string ("").

Log

An empty string ("").

MachineName

The local computer (".").

The following example creates the source MySource if it does not already exist, and writes an entry to the event log MyNewLog.

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.");

    }
}

EventLogPermission

for writing the event log information on the computer. Associated enumeration: F:System.Diagnostics.EventLogPermissionAccess.Write

.NET Framework
Disponibile da 1.1
Torna all'inizio
Mostra: