EventLog Konstruktor
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menginisialisasi instans baru kelas EventLog.
Overload
EventLog() |
Menginisialisasi instans baru kelas EventLog. Tidak mengaitkan instans dengan log apa pun. |
EventLog(String) |
Menginisialisasi instans baru kelas EventLog. Mengaitkan instans dengan log di komputer lokal. |
EventLog(String, String) |
Menginisialisasi instans baru kelas EventLog. Mengaitkan instans dengan log pada komputer yang ditentukan. |
EventLog(String, String, String) |
Menginisialisasi instans baru kelas EventLog. Mengaitkan instans dengan log di komputer yang ditentukan dan membuat atau menetapkan sumber yang ditentukan ke EventLog. |
EventLog()
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
Menginisialisasi instans baru kelas EventLog. Tidak mengaitkan instans dengan log apa pun.
public:
EventLog();
public EventLog ();
Public Sub New ()
Contoh
Contoh berikut membuat sumber MySource
jika belum ada, dan menulis entri ke log MyNewLog
peristiwa .
#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
Keterangan
Sebelum memanggil WriteEntry, tentukan Source properti EventLog instans. Jika Anda hanya membaca Entries dari log, Anda dapat menentukan properti Log dan MachineName saja.
Catatan
Jika Anda tidak menentukan MachineName, komputer lokal (".") diasumsikan.
Tabel berikut ini memperlihatkan nilai properti awal untuk instans EventLog.
Properti | Nilai Awal |
---|---|
Source | String kosong (""). |
Log | String kosong (""). |
MachineName | Komputer lokal ("."). |
Lihat juga
Berlaku untuk
EventLog(String)
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
Menginisialisasi instans baru kelas EventLog. Mengaitkan instans dengan log di komputer lokal.
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
Nama log pada komputer lokal.
Pengecualian
Nama log adalah null
.
Nama log tidak valid.
Contoh
Contoh berikut membaca entri dalam log peristiwa, "myNewLog", di komputer lokal.
#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
Keterangan
Kelebihan beban ini mengatur Log properti ke logName
parameter . Sebelum memanggil WriteEntry, tentukan Source properti EventLog instans. Jika Anda hanya membaca Entries dari log, Anda dapat menentukan properti Log dan MachineName saja.
Catatan
Jika Anda tidak menentukan MachineName, komputer lokal (".") diasumsikan. Kelebihan beban konstruktor ini menentukan Log properti , tetapi Anda dapat mengubah ini sebelum membaca Entries properti .
Jika sumber yang Anda tentukan di Source properti unik dari sumber lain di komputer, panggilan berikutnya untuk WriteEntry membuat log dengan nama yang ditentukan, jika belum ada.
Tabel berikut ini memperlihatkan nilai properti awal untuk instans EventLog.
Properti | Nilai Awal |
---|---|
Source | String kosong (""). |
Log | Parameter .logName |
MachineName | Komputer lokal ("."). |
Lihat juga
Berlaku untuk
EventLog(String, String)
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
Menginisialisasi instans baru kelas EventLog. Mengaitkan instans dengan log pada komputer yang ditentukan.
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
Nama log pada komputer yang ditentukan.
- machineName
- String
Komputer tempat log berada.
Pengecualian
Nama log adalah null
.
Contoh
Contoh berikut membaca entri dalam log peristiwa, "myNewLog", di komputer "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
Keterangan
Kelebihan beban ini mengatur Log properti ke logName
parameter dan MachineName properti ke machineName
parameter . Sebelum memanggil WriteEntry, tentukan Source properti dari EventLog. Jika Anda hanya membaca Entries dari log, Anda dapat menentukan properti Log dan MachineName saja.
Catatan
Kelebihan beban konstruktor ini menentukan Log properti dan MachineName , tetapi Anda dapat mengubah baik sebelum membaca Entries properti .
Tabel berikut ini memperlihatkan nilai properti awal untuk instans EventLog.
Properti | Nilai Awal |
---|---|
Source | String kosong (""). |
Log | Parameter .logName |
MachineName | Parameter .machineName |
Lihat juga
Berlaku untuk
EventLog(String, String, String)
- Sumber:
- EventLog.cs
- Sumber:
- EventLog.cs
- Sumber:
- 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)
Parameter
- logName
- String
Nama log pada komputer yang ditentukan.
- machineName
- String
Komputer tempat log berada.
- source
- String
Sumber entri log peristiwa.
Pengecualian
Nama log adalah null
.
Contoh
Contoh berikut menulis entri ke log peristiwa, "MyNewLog", di komputer lokal, menggunakan sumber "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
Keterangan
Konstruktor ini mengatur Log properti ke logName
parameter , MachineName properti ke machineName
parameter , dan Source properti ke source
parameter . Properti Source diperlukan saat menulis ke log peristiwa. Namun, jika Anda hanya membaca dari log peristiwa, hanya Log properti dan MachineName yang diperlukan (selama log peristiwa di server memiliki sumber yang sudah terkait dengannya). Jika Anda hanya membaca dari log peristiwa, kelebihan konstruktor lain mungkin sudah cukup.
Tabel berikut ini memperlihatkan nilai properti awal untuk instans EventLog.
Properti | Nilai Awal |
---|---|
Source | Parameter .source |
Log | Parameter .logName |
MachineName | Parameter .machineName |