コンピュータのレジストリ内で、指定したイベント ソースを検索します。
オーバーロードの一覧
ローカル コンピュータにイベント ソースが登録されているかどうかを確認します。
[Visual Basic] Overloads Public Shared Function SourceExists(String) As Boolean
[JScript] public static function SourceExists(String) : Boolean;
指定したコンピュータにイベント ソースが登録されているかどうかを確認します。
[Visual Basic] Overloads Public Shared Function SourceExists(String, String) As Boolean
[JScript] public static function SourceExists(String, String) : Boolean;
使用例
[Visual Basic, C#, C++] コンピュータ "MyServer" 上のイベント ログ "MyNewLog" にエントリを書き込み、ソースがまだ存在しない場合はソース "MySource" を作成する例を次に示します。
[Visual Basic, C#, C++] メモ コード内でイベント ソースを作成する必要はありません。 Source プロパティで設定したソースが存在しない場合、 WriteEntry メソッドは、イベント ログに書き込む前に、そのソースを作成します。 EventLog インスタンスの Log プロパティを指定しない場合、ログは既定によりアプリケーション ログになります。
[Visual Basic, C#, C++] メモ ここでは、SourceExists のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。
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", "MyServer") Then
EventLog.CreateEventSource("MySource", "MyNewLog", "MyServer")
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.")
Console.WriteLine("Message written to event log.")
End Sub ' Main
End Class ' MySample
[C#]
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", "MyServer")){
EventLog.CreateEventSource("MySource", "MyNewLog", "MyServer");
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.");
Console.WriteLine("Message written to event log.");
}
}
[C++]
#using <mscorlib.dll>
#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(S"MySource", S"MyServer")){
EventLog::CreateEventSource(S"MySource", S"MyNewLog", S"MyServer");
Console::WriteLine(S"CreatingEventSource");
}
// Create an EventLog instance and assign its source.
EventLog* myLog = new EventLog();
myLog->Source = S"MySource";
// Write an informational entry to the event log.
myLog->WriteEntry(S"Writing to event log.");
Console::WriteLine(S"Message written to event log.");
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。