EventLog Constructeurs
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Initialise une nouvelle instance de la classe EventLog.
Surcharges
EventLog() |
Initialise une nouvelle instance de la classe EventLog. N'associe pas l'instance à un journal. |
EventLog(String) |
Initialise une nouvelle instance de la classe EventLog. Associe l'instance à un journal sur l'ordinateur local. |
EventLog(String, String) |
Initialise une nouvelle instance de la classe EventLog. Associe l'instance à un journal sur l'ordinateur spécifié. |
EventLog(String, String, String) |
Initialise une nouvelle instance de la classe EventLog. Associe l'instance à un journal sur l'ordinateur spécifié et crée ou assigne la source spécifiée à EventLog. |
EventLog()
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
Initialise une nouvelle instance de la classe EventLog. N'associe pas l'instance à un journal.
public:
EventLog();
public EventLog ();
Public Sub New ()
Exemples
L’exemple suivant crée la source MySource
si elle n’existe pas déjà et écrit une entrée dans le journal MyNewLog
des événements .
#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
Remarques
Avant d’appeler WriteEntry, spécifiez la Source propriété du EventLog instance. Si vous lisez uniquement Entries à partir du journal, vous pouvez également spécifier uniquement les Log propriétés et MachineName .
Notes
Si vous ne spécifiez pas de MachineName, l’ordinateur local (« . ») est supposé.
Le tableau suivant montre les valeurs de propriété initiales d’un instance de EventLog.
Propriété | Valeur initiale |
---|---|
Source | Une chaîne vide (""). |
Log | Une chaîne vide (""). |
MachineName | L’ordinateur local (« . »). |
Voir aussi
S’applique à
EventLog(String)
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
Initialise une nouvelle instance de la classe EventLog. Associe l'instance à un journal sur l'ordinateur local.
public:
EventLog(System::String ^ logName);
public EventLog (string logName);
new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog
Public Sub New (logName As String)
Paramètres
- logName
- String
Nom du journal sur l'ordinateur local.
Exceptions
Le nom de journal a la valeur null
.
Le nom de journal est non valide.
Exemples
L’exemple suivant lit les entrées dans le journal des événements, « myNewLog », sur l’ordinateur local.
#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
Remarques
Cette surcharge définit la Log propriété sur le logName
paramètre . Avant d’appeler WriteEntry, spécifiez la Source propriété du EventLog instance. Si vous lisez uniquement Entries à partir du journal, vous pouvez également spécifier uniquement les Log propriétés et MachineName .
Notes
Si vous ne spécifiez pas de MachineName, l’ordinateur local (« . ») est supposé. Cette surcharge du constructeur spécifie la Log propriété, mais vous pouvez la modifier avant de lire la Entries propriété.
Si la source que vous spécifiez dans la Source propriété est unique à partir d’autres sources sur l’ordinateur, un appel WriteEntry suivant crée un journal avec le nom spécifié, s’il n’existe pas déjà.
Le tableau suivant montre les valeurs de propriété initiales d’un instance de EventLog.
Propriété | Valeur initiale |
---|---|
Source | Une chaîne vide (""). |
Log | Paramètre logName . |
MachineName | L’ordinateur local (« . »). |
Voir aussi
S’applique à
EventLog(String, String)
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
Initialise une nouvelle instance de la classe EventLog. Associe l'instance à un journal sur l'ordinateur spécifié.
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)
Paramètres
- logName
- String
Nom du journal sur l'ordinateur spécifié.
- machineName
- String
Ordinateur sur lequel se trouve le journal.
Exceptions
Le nom de journal a la valeur null
.
Exemples
L’exemple suivant lit les entrées dans le journal des événements, « myNewLog », sur l’ordinateur « myServer ».
#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
Remarques
Cette surcharge définit la Log propriété sur le logName
paramètre et la MachineName propriété sur le machineName
paramètre. Avant d’appeler WriteEntry, spécifiez la Source propriété de .EventLog Si vous lisez uniquement Entries à partir du journal, vous pouvez également spécifier uniquement les Log propriétés et MachineName .
Notes
Cette surcharge du constructeur spécifie les propriétés etMachineName, mais vous pouvez modifier l’une ou l’autre Log avant de lire la Entries propriété.
Le tableau suivant montre les valeurs de propriété initiales d’un instance de EventLog.
Propriété | Valeur initiale |
---|---|
Source | Une chaîne vide (""). |
Log | Paramètre logName . |
MachineName | Paramètre machineName . |
Voir aussi
S’applique à
EventLog(String, String, String)
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
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)
Paramètres
- logName
- String
Nom du journal sur l'ordinateur spécifié.
- machineName
- String
Ordinateur sur lequel se trouve le journal.
- source
- String
Source des entrées du journal des événements.
Exceptions
Le nom de journal a la valeur null
.
Exemples
L’exemple suivant écrit une entrée dans un journal des événements, « MyNewLog », sur l’ordinateur local, à l’aide de la source « MySource ».
#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
Remarques
Ce constructeur définit la Log propriété sur le logName
paramètre, la MachineName propriété sur le machineName
paramètre et la Source propriété sur le source
paramètre. La Source propriété est requise lors de l’écriture dans un journal des événements. Toutefois, si vous lisez uniquement à partir d’un journal des événements, seules les Log propriétés et MachineName sont requises (tant que le journal des événements sur le serveur a déjà une source associée). Si vous lisez uniquement à partir du journal des événements, une autre surcharge du constructeur peut suffire.
Le tableau suivant montre les valeurs de propriété initiales d’un instance de EventLog.
Propriété | Valeur initiale |
---|---|
Source | Paramètre source . |
Log | Paramètre logName . |
MachineName | Paramètre machineName . |