NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

EventLog.CreateEventSource

Establishes an application as an event source.

Overload List

Establishes an application as an event source with the specified Source. Registers the source to a Log that resides on the computer specified by machineName. This method can also be used to create a new custom log on the given computer.

[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);

Establishes an application as an event source with the specified Source. Registers the source to a Log that resides on the local computer. This method can also be used to create a new custom log on the local computer.

[Visual Basic] Overloads Public Shared Sub CreateEventSource(String, String)
[C#] public static void CreateEventSource(String, String);
[C++] public: static void CreateEventSource(String*, String*);
[JScript] public static function CreateEventSource(String, String);

Example [Visual Basic]

The following example connects to an event log, "myNewLog", on the local computer. If the source "myNewSource" does not already exist on the computer, it is created. Then, an entry is written to the Log.

Note that the way to create a new event log is through the static (in Visual Basic Shared) member CreateEventSource, which creates a Source and registers it to the Log at the time the log is created. Because this is a static (Shared) member of EventLog, it should be called on the class itself rather than on an instance of the class.

Import the System.Diagnostics namespace for this example.

Note   This example shows how to use one of the overloaded versions of CreateEventSource. For other examples that may be available, see the individual overload topics.

[Visual Basic]

Private Sub ConnectToEventLog()
    'Declare a new event log and event log entry.
    Dim evtLog As EventLog

    'Instantiate a new event log.
    evtLog = New EventLog

    'Otherwise, create a new source and log.
    If Not EventLog.SourceExists("myNewSource") Then
        'If MyNewLog does not exist, it will be created
        EventLog.CreateEventSource("myNewSource", "myNewLog")
    End If
    
    'Connect the source to the event instance.
    evtLog.Source = "myNewSource"
    
    'Write an entry to the event log.
    evtLog.WriteEntry("Event log entry.")
End Sub

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace