次の方法で共有


EventLog コンストラクタ ()

EventLog クラスの新しいインスタンスを初期化します。このインスタンスは、ログとは関連付けられません。

名前空間: System.Diagnostics
アセンブリ: System (system.dll 内)

構文

'宣言
Public Sub New
'使用
Dim instance As New EventLog
public EventLog ()
public:
EventLog ()
public EventLog ()
public function EventLog ()

解説

WriteEntry を呼び出す前に、EventLog インスタンスの Source プロパティを指定します。ログから Entries だけを読み取る場合は、Log プロパティと MachineName プロパティだけを指定する方法もあります。

注意

MachineName を指定しなかった場合は、ローカル コンピュータ (".") が想定されます。

EventLog のインスタンスの初期プロパティ値を次の表に示します。

プロパティ

初期値

Source

空の文字列 ("")。

Log

空の文字列 ("")。

MachineName

ローカル コンピュータ (".")。

使用例

ソースが存在しない場合は 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

.NET Framework のセキュリティ

プラットフォーム

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0

参照

関連項目

EventLog クラス
EventLog メンバ
System.Diagnostics 名前空間
Source
Log
MachineName
Entries
WriteEntry
WriteEvent
EventLogEntry