EventLog コンストラクタ ()
アセンブリ: System (system.dll 内)


WriteEntry を呼び出す前に、EventLog インスタンスの Source プロパティを指定します。ログから Entries だけを読み取る場合は、Log プロパティと MachineName プロパティだけを指定する方法もあります。
![]() |
---|
EventLog のインスタンスの初期プロパティ値を次の表に示します。

ソースが存在しない場合は MySource を作成し、イベント ログ MyNewLog にエントリを書き込む例を次に示します。
Option Explicit Option Strict Imports System Imports System.Diagnostics Imports System.Threading Class MySample Public Shared Sub Main() ' Create the source, if it does not already exist. If Not EventLog.SourceExists("MySource") Then EventLog.CreateEventSource("MySource", "MyNewLog") Console.WriteLine("CreatingEventSource") 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 'Main End Class 'MySample
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")){ EventLog.CreateEventSource("MySource", "MyNewLog"); Console.WriteLine("CreatingEventSource"); } // 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."); } }
#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" ) ) { EventLog::CreateEventSource( "MySource", "MyNewLog" ); Console::WriteLine( "CreatingEventSource" ); } // 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." ); }
import System.*; import System.Diagnostics.*; import System.Threading.*; class MySample { public static void main(String[] args) { // Create the source, if it does not already exist. if (!(EventLog.SourceExists("MySource"))) { EventLog.CreateEventSource("MySource", "MyNewLog"); Console.WriteLine("CreatingEventSource"); } // Create an EventLog instance and assign its source. EventLog myLog = new EventLog(); myLog.set_Source("MySource"); // Write an informational entry to the event log. myLog.WriteEntry("Writing to event log."); } //main } //MySample


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


EventLog コンストラクタ (String, String)
アセンブリ: System (system.dll 内)



このオーバーロードは、Log プロパティにlogName パラメータを設定し、MachineName プロパティに machineName パラメータを設定します。WriteEntry を呼び出す前に、EventLog の Source プロパティを指定します。ログから Entries だけを読み取る場合は、Log プロパティと MachineName プロパティだけを指定する方法もあります。
![]() |
---|
このコンストラクタのオーバーロードで Log プロパティおよび MachineName プロパティが指定されますが、どちらも Entries プロパティを読み取る前に変更できます。 |
EventLog のインスタンスの初期プロパティ値を次の表に示します。

コンピュータ "myServer" 上のイベント ログ "myNewLog" のエントリを読み取る例を次に示します。
Option Explicit Option Strict Imports System Imports System.Diagnostics Imports System.Threading Imports Microsoft.VisualBasic Class MySample Public Shared Sub Main() ' 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 ' Main End Class ' MySample
using System; using System.Diagnostics; using System.Threading; class MySample{ public static void Main(){ // 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); } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::Threading; int main() { // 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 ); } }
import System.*; import System.Diagnostics.*; import System.Threading.*; class MySample { public static void main(String[] args) { // Create an EventLog instance and assign its log name. EventLog myLog = new EventLog("myNewLog", "myServer"); // Read the event log entries. for (int iCtr = 0; iCtr < myLog.get_Entries().get_Count(); iCtr++) { EventLogEntry entry = myLog.get_Entries().get_Item(iCtr); Console.WriteLine("\tEntry: " + entry.get_Message()); } } //main } //MySample


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


EventLog コンストラクタ (String)
アセンブリ: System (system.dll 内)



このオーバーロードは、Log プロパティに logName パラメータを設定します。WriteEntry を呼び出す前に、EventLog インスタンスの Source プロパティを指定します。ログから Entries だけを読み取る場合は、Log プロパティと MachineName プロパティだけを指定する方法もあります。
![]() |
---|
MachineName を指定しなかった場合は、ローカル コンピュータ (".") が想定されます。このコンストラクタのオーバーロードで Log プロパティが指定されますが、このプロパティは Entries プロパティを読み取る前に変更できます。 |
Source プロパティに指定したソースがコンピュータ上の他のソースとは異なる一意のソースである場合、後続の WriteEntry 呼び出しで、指定した名前のログが作成されます (ログがまだ存在しない場合)。
EventLog のインスタンスの初期プロパティ値を次の表に示します。

ローカル コンピュータ上のイベント ログ "myNewLog" のエントリを読み取る例を次に示します。
Option Explicit Option Strict Imports System Imports System.Diagnostics Imports System.Threading Imports Microsoft.VisualBasic Class MySample Public Shared Sub Main() ' Create an EventLog instance and assign its log name. 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 ' Main End Class ' MySample
using System; using System.Diagnostics; using System.Threading; class MySample{ public static void Main(){ // 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); } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::Threading; int main() { // 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 ); } }
import System.*; import System.Diagnostics.*; import System.Threading.*; class MySample { public static void main(String[] args) { // Create an EventLog instance and assign its log name. EventLog myLog = new EventLog("myNewLog"); // Read the event log entries. for (int iCtr = 0; iCtr < myLog.get_Entries().get_Count(); iCtr++) { EventLogEntry entry = myLog.get_Entries().get_Item(iCtr); Console.WriteLine("\tEntry: " + entry.get_Message()); } } //main } //MySample


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


EventLog コンストラクタ

名前 | 説明 |
---|---|
EventLog () | EventLog クラスの新しいインスタンスを初期化します。このインスタンスは、ログとは関連付けられません。 |
EventLog (String) | EventLog クラスの新しいインスタンスを初期化します。ローカル コンピュータ上のログにインスタンスを関連付けます。 |
EventLog (String, String) | EventLog クラスの新しいインスタンスを初期化します。指定したコンピュータ上のログにインスタンスを関連付けます。 |
EventLog (String, String, String) | EventLog クラスの新しいインスタンスを初期化します。指定したコンピュータ上のログにインスタンスを関連付け、指定したソースを作成するか、または EventLog に割り当てます。 |

EventLog コンストラクタ (String, String, String)
アセンブリ: System (system.dll 内)

Dim logName As String Dim machineName As String Dim source As String Dim instance As New EventLog(logName, machineName, source)


このコンストラクタは、Log プロパティに logName パラメータを設定し、MachineName プロパティに machineName パラメータを設定し、Source プロパティに source を設定します。Source プロパティは、イベント ログに書き込むときに必要です。しかし、イベント ログを読み取るだけの場合は、Log プロパティと MachineName プロパティだけが必要です (サーバー上のイベント ログに、そのログに関連付けられているソースが既に存在する場合)。イベント ログを読み取るだけの場合は、コンストラクタのもう 1 つのオーバーロードを使用するだけで十分です。
EventLog のインスタンスの初期プロパティ値を次の表に示します。

ソース "MySource" を使用して、ローカル コンピュータ上のイベント ログ "MyNewLog" にエントリを書き込む例を次に示します。
Option Strict Option Explicit Imports System Imports System.Diagnostics Imports System.Threading Class MySample Public Shared Sub Main() ' 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 ' Main End Class ' MySample
using System; using System.Diagnostics; using System.Threading; class MySample{ public static void Main(){ // 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); } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::Threading; int main() { // 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 ) ); }
import System.*; import System.Diagnostics.*; import System.Threading.*; class MySample { public static void main(String[] args) { // 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.get_MachineName()); } //main } //MySample


Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- EventLog コンストラクタ ()のページへのリンク