EventLog.EnableRaisingEvents Propiedad
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Obtiene o establece un valor que indica si EventLog recibe notificaciones de eventos EntryWritten.
public:
property bool EnableRaisingEvents { bool get(); void set(bool value); };
[System.ComponentModel.Browsable(false)]
public bool EnableRaisingEvents { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.EnableRaisingEvents : bool with get, set
Public Property EnableRaisingEvents As Boolean
Valor de propiedad
Es true si EventLog recibe la notificación cuando se escribe una entrada en el registro; en caso contrario, es false.
- Atributos
Excepciones
El registro de eventos está en un equipo remoto.
Ejemplos
En el ejemplo siguiente se controla un EntryWritten evento.
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
ref class MySample
{
public:
static void MyOnEntryWritten( Object^ /*source*/, EntryWrittenEventArgs^ e )
{
Console::WriteLine( "Written: {0}", e->Entry->Message );
}
};
int main()
{
EventLog^ myNewLog = gcnew EventLog;
myNewLog->Log = "MyCustomLog";
myNewLog->EntryWritten += gcnew EntryWrittenEventHandler( MySample::MyOnEntryWritten );
myNewLog->EnableRaisingEvents = true;
Console::WriteLine( "Press \'q\' to quit." );
// Wait for the EntryWrittenEvent or a quit command.
while ( Console::Read() != 'q' )
{
// Wait.
}
}
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);
}
}
Option Strict
Option Explicit
Imports System.Diagnostics
Imports System.Threading
Class MySample
Public Shared Sub Main()
Dim myNewLog As New EventLog()
myNewLog.Log = "MyCustomLog"
AddHandler myNewLog.EntryWritten, AddressOf MyOnEntryWritten
myNewLog.EnableRaisingEvents = True
Console.WriteLine("Press 'q' to quit.")
' Wait for the EntryWrittenEvent or a quit command.
While Char.ToLower(Convert.ToChar(Console.Read()))<>"q"
' Wait.
End While
End Sub
Public Shared Sub MyOnEntryWritten(source As Object, e As EntryWrittenEventArgs)
Console.WriteLine(("Written: " + e.Entry.Message))
End Sub
End Class
Comentarios
La EnableRaisingEvents propiedad determina si EventLog genera eventos cuando se escriben entradas en el registro. Cuando la propiedad es true, los componentes que reciben el EntryWritten evento recibirán una notificación cada vez que se escriba una entrada en el registro especificado en la Log propiedad . Si EnableRaisingEvents es false, no se generan eventos.
Nota
Solo puede recibir notificaciones de eventos cuando se escriben entradas en el equipo local. No puede recibir notificaciones de entradas escritas en equipos remotos.