EventLog コンストラクター
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
EventLog クラスの新しいインスタンスを初期化します。
オーバーロード
| 名前 | 説明 |
|---|---|
| EventLog() |
EventLog クラスの新しいインスタンスを初期化します。 インスタンスをログに関連付けません。 |
| EventLog(String) |
EventLog クラスの新しいインスタンスを初期化します。 インスタンスをローカル コンピューター上のログに関連付けます。 |
| EventLog(String, String) |
EventLog クラスの新しいインスタンスを初期化します。 指定したコンピューター上のログにインスタンスを関連付けます。 |
| EventLog(String, String, String) |
EventLog クラスの新しいインスタンスを初期化します。 指定したコンピューター上のログにインスタンスを関連付け、指定したソースを作成するか、 EventLogに割り当てます。 |
EventLog()
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
EventLog クラスの新しいインスタンスを初期化します。 インスタンスをログに関連付けません。
public:
EventLog();
public EventLog();
Public Sub New ()
例
次の例では、ソース MySource がまだ存在しない場合は作成し、イベント ログ MyNewLogにエントリを書き込みます。
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
注釈
WriteEntryを呼び出す前に、EventLog インスタンスのSource プロパティを指定します。 ログから Entries のみを読み取る場合は、 Log と MachineName のプロパティのみを指定することもできます。
注
MachineNameを指定しない場合は、ローカル コンピューター (".") が想定されます。
次の表に、 EventLogのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
| Source | 空の文字列 ("")。 |
| Log | 空の文字列 ("")。 |
| MachineName | ローカル コンピューター (".")。 |
こちらもご覧ください
適用対象
EventLog(String)
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
EventLog クラスの新しいインスタンスを初期化します。 インスタンスをローカル コンピューター上のログに関連付けます。
public:
EventLog(System::String ^ logName);
public EventLog(string logName);
new System.Diagnostics.EventLog : string -> System.Diagnostics.EventLog
Public Sub New (logName As String)
パラメーター
- logName
- String
ローカル コンピューター上のログの名前。
例外
ログ名は null。
ログ名が無効です。
例
次の例では、ローカル コンピューター上のイベント ログ "myNewLog" のエントリを読み取ります。
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
注釈
このオーバーロードは、 Log プロパティを logName パラメーターに設定します。
WriteEntryを呼び出す前に、EventLog インスタンスのSource プロパティを指定します。 ログから Entries のみを読み取る場合は、 Log と MachineName のプロパティのみを指定することもできます。
注
MachineNameを指定しない場合は、ローカル コンピューター (".") が想定されます。 コンストラクターのこのオーバーロードは、 Log プロパティを指定しますが、 Entries プロパティを読み取る前にこれを変更できます。
Source プロパティで指定したソースがコンピューター上の他のソースから一意である場合、WriteEntryを呼び出すと、指定した名前のログがまだ存在しない場合に作成されます。
次の表に、 EventLogのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
| Source | 空の文字列 ("")。 |
| Log |
logName パラメーター。 |
| MachineName | ローカル コンピューター (".")。 |
こちらもご覧ください
適用対象
EventLog(String, String)
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
EventLog クラスの新しいインスタンスを初期化します。 指定したコンピューター上のログにインスタンスを関連付けます。
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)
パラメーター
- logName
- String
指定したコンピューター上のログの名前。
- machineName
- String
ログが存在するコンピューター。
例外
ログ名は null。
例
次の例では、コンピューター "myServer" のイベント ログ "myNewLog" のエントリを読み取ります。
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
注釈
このオーバーロードでは、 Log プロパティを logName パラメーターに、 MachineName プロパティを machineName パラメーターに設定します。
WriteEntryを呼び出す前に、EventLogのSource プロパティを指定します。 ログから Entries のみを読み取る場合は、 Log と MachineName のプロパティのみを指定することもできます。
注
コンストラクターのこのオーバーロードは、 Log プロパティと MachineName プロパティを指定しますが、 Entries プロパティを読み取る前に変更できます。
次の表に、 EventLogのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
| Source | 空の文字列 ("")。 |
| Log |
logName パラメーター。 |
| MachineName |
machineName パラメーター。 |
こちらもご覧ください
適用対象
EventLog(String, String, String)
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- EventLog.cs
- ソース:
- 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)
パラメーター
- logName
- String
指定したコンピューター上のログの名前。
- machineName
- String
ログが存在するコンピューター。
- source
- String
イベント ログ エントリのソース。
例外
ログ名は null。
例
次の例では、ソース "MySource" を使用して、ローカル コンピューター上のイベント ログ "MyNewLog" にエントリを書き込みます。
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
注釈
このコンストラクターは、 Log プロパティを logName パラメーターに設定し、 MachineName プロパティを machineName パラメーターに設定し、 Source プロパティを source パラメーターに設定します。 イベント ログに書き込む場合は、 Source プロパティが必要です。 ただし、イベント ログからのみ読み取る場合は、 Log プロパティと MachineName プロパティのみが必要です (サーバー上のイベント ログに既にソースが関連付けられている場合)。 イベント ログからのみ読み取る場合は、コンストラクターの別のオーバーロードで十分な場合があります。
次の表に、 EventLogのインスタンスの初期プロパティ値を示します。
| 財産 | 初期値 |
|---|---|
| Source |
source パラメーター。 |
| Log |
logName パラメーター。 |
| MachineName |
machineName パラメーター。 |