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.DeleteEventSource (String, String)

Removes the application's event source registration from the specified computer.

[Visual Basic]
Overloads Public Shared Sub DeleteEventSource( _
   ByVal source As String, _
   ByVal machineName As String _
)
[C#]
public static void DeleteEventSource(
   string source,
   string machineName
);
[C++]
public: static void DeleteEventSource(
   String* source,
   String* machineName
);
[JScript]
public static function DeleteEventSource(
   source : String,
   machineName : String
);

Parameters

source
The name the application is registered with in the event log system.
machineName
The name of the computer to remove the registration from, or a null reference (in Visual Basic Nothing) for the local computer.

Exceptions

Exception Type Condition
ArgumentException The machineName parameter is invalid.
ArgumentException The source parameter does not exist in the registry of the specified computer.
ArgumentException You do not have write access on the registry key for the event log.

Remarks

Use this overload to remove the registration of a Source from a remote computer. DeleteEventSource accesses the registry on the computer specified by machineName and removes the registration of your application as a valid source of events.

You can remove your component as a valid source of events if you no longer need to use it to write entries to that log. You might do this if you were changing your component from one log to another. Because a source can only be registered to one log at a time, changing the log requires removing the current registration.

DeleteEventSource removes only the source registered to a log. If you want to remove the log itself, call Delete. If you only want to delete the log entries, call Clear. Delete and DeleteEventSource are static (in Visual Basic Shared) methods, so they can be called on the class itself. It is not necessary to instantiate EventLog to call either method.

Deleting a log through a call to Delete does not automatically delete the sources registered to that log. If you want to delete a log, you should first call DeleteEventSource separately for all sources registered to the log.

Example [Visual Basic]

The following example closes an event log specified by the source "mySource" on the computer "myComputer", and deletes the source. This does not delete the log to which the source is registered (use Delete for that), only the source and its registration. The log can be opened again by creating another source using CreateEventSource and registering it to the log.

The local event log instance is created only in order to call Close on the log. All other methods used are static (Shared) and should be called on the EventLog class itself.

Import the System.Diagnostics namespace for this example.

[Visual Basic]

Private Sub CloseLog()
    'Declare and instantiate an event log.
    Dim evtLog As EventLog
    evtLog = New EventLog
    'Declare a source called "mySource"
    Dim source As String
    source = "mySource"
    'Declare a computer called "myComputer"
    Dim computer As String
    computer = "myComputer"

    'Verify that the source exists.
    If EventLog.SourceExists(source, computer) Then
        'Connect the event log to the source.
        evtLog.Source = source
        'Close the log so that it does not receive new entries.
        evtLog.Close()
        EventLog.DeleteEventSource(source, computer)
    End If
End Sub

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.DeleteEventSource Overload List | CreateEventSource | Source | SourceExists | Delete | Clear