Läs på engelska Redigera

Dela via


EventLog.EnableRaisingEvents Property

Definition

Gets or sets a value indicating whether the EventLog receives EntryWritten event notifications.

C#
[System.ComponentModel.Browsable(false)]
public bool EnableRaisingEvents { get; set; }

Property Value

true if the EventLog receives notification when an entry is written to the log; otherwise, false.

Attributes

Exceptions

The event log is on a remote computer.

Examples

The following example handles an EntryWritten event.

C#
using System;
using System.Diagnostics;
using System.Threading;

class MySample{

    public static void Main(){

        EventLog myNewLog = new EventLog();
        myNewLog.Log = "MyCustomLog";

        myNewLog.EntryWritten += new EntryWrittenEventHandler(MyOnEntryWritten);
        myNewLog.EnableRaisingEvents = true;

        Console.WriteLine("Press \'q\' to quit.");
        // Wait for the EntryWrittenEvent or a quit command.
        while(Console.Read() != 'q'){
            // Wait.
        }
    }

    public static void MyOnEntryWritten(Object source, EntryWrittenEventArgs e){
        Console.WriteLine("Written: " + e.Entry.Message);
    }
}

Remarks

The EnableRaisingEvents property determines whether the EventLog raises events when entries are written to the log. When the property is true, components that receive the EntryWritten event will receive notification any time an entry is written to the log that is specified in the Log property. If EnableRaisingEvents is false, no events are raised.

Anteckning

You can receive event notifications only when entries are written on the local computer. You cannot receive notifications for entries written on remote computers.

Applies to

Produkt Versioner
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also