システム上の特定のログにイベント情報を書き込むことができるようにアプリケーションを設定します。
オーバーロードの一覧
指定した Source を、ローカル コンピュータ上のログにエントリを書き込むための有効なイベント ソースとして使用して、アプリケーションを設定します。また、このメソッドによってローカル コンピュータ上に新しいカスタム ログを作成することもできます。
[Visual Basic] Overloads Public Shared Sub CreateEventSource(String, String)
[C++] public: static void CreateEventSource(String*, String*);
[JScript] public static function CreateEventSource(String, String);
指定した Source を、 machineName で指定されるコンピュータ上のログにエントリを書き込むための有効なイベント ソースとして使用し、アプリケーションを設定します。このメソッドを使用して、指定したコンピュータ上に新しいカスタム ログを作成することもできます。
[Visual Basic] Overloads Public Shared Sub CreateEventSource(String, String, String)
[C#] public static void CreateEventSource(string, string, string);
[C++] public: static void CreateEventSource(String*, String*, String*);
[JScript] public static function CreateEventSource(String, String, String);
使用例
[Visual Basic, C#, C++] コンピュータ "MyServer" 上のイベント ログ "MyNewLog" にエントリを書き込み、ソースがまだ存在しない場合はソース "MySource" を作成する例を次に示します。
[Visual Basic, C#, C++] メモ コード内でイベント ソースを作成する必要はありません。 Source プロパティで設定したソースが存在しない場合、 WriteEntry メソッドは、イベント ログに書き込む前に、そのソースを作成します。 EventLog インスタンスの Log プロパティを指定しない場合、ログは既定によりアプリケーション ログになります。
[Visual Basic, C#, C++] メモ ここでは、CreateEventSource のオーバーロード形式のうちの 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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン
をクリックします。