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.SourceExists

Searches a computer's registry for a given event source.

Overload List

Determines whether an event source is registered on the local computer.

[Visual Basic] Overloads Public Shared Function SourceExists(String) As Boolean
[C#] public static bool SourceExists(String);
[C++] public: static bool SourceExists(String*);
[JScript] public static function SourceExists(String) : Boolean;

Determines whether an event source is registered on a specified computer.

[Visual Basic] Overloads Public Shared Function SourceExists(String, String) As Boolean
[C#] public static bool SourceExists(String, String);
[C++] public: static bool SourceExists(String*, String*);
[JScript] public static function SourceExists(String, String) : Boolean;

Example [Visual Basic]

The following example connects to an event log, "myNewLog", on the computer "myComputer". 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 SourceExists. 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", "myComputer") Then
        'If MyNewLog does not exist, it will be created
        EventLog.CreateEventSource("myNewSource", "myComputer", "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