EventLog Constructor
Initializes a new instance of the EventLog class.
Overload List
Initializes a new instance of the EventLog class. Does not associate the instance with any log.
[Visual Basic] Public Sub New()
[C#] public EventLog();
[C++] public: EventLog();
[JScript] public function EventLog();
Initializes a new instance of the EventLog class. Associates the instance with a log on the local computer.
[Visual Basic] Public Sub New(String)
[C#] public EventLog(string);
[C++] public: EventLog(String*);
[JScript] public function EventLog(String);
Initializes a new instance of the EventLog class. Associates the instance with a log on the specified computer.
[Visual Basic] Public Sub New(String, String)
[C#] public EventLog(string, string);
[C++] public: EventLog(String*, String*);
[JScript] public function EventLog(String, String);
Initializes a new instance of the EventLog class. Associates the instance with a log on the specified computer and creates or assigns the specified source to the EventLog.
[Visual Basic] Public Sub New(String, String, String)
[C#] public EventLog(string, string, string);
[C++] public: EventLog(String*, String*, String*);
[JScript] public function EventLog(String, String, String);
Example
[Visual Basic, C#, C++] The following example writes an entry to an event log, "MyNewLog", on the local computer, using the source "MySource".
[Visual Basic, C#, C++] Note If "MySource" does not already exist, the WriteEntry method creates it before writing to the event log.
[Visual Basic, C#, C++] Note This example shows how to use one of the overloaded versions of the EventLog constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 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 [C#] 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); } } [C++] #using <mscorlib.dll> #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 = new EventLog(S"myNewLog", S".", S"MySource"); // Write an entry to the log. myLog->WriteEntry(String::Format( S"Writing to event log on {0}", myLog->MachineName )); }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
See Also
EventLog Class | EventLog Members | System.Diagnostics Namespace