Removes the event source registration from the event log of the local computer.
[Visual Basic] Overloads Public Shared Sub DeleteEventSource( _ ByVal source As String _ ) [C#] public static void DeleteEventSource( string source ); [C++] public: static void DeleteEventSource( String* source ); [JScript] public static function DeleteEventSource( source : String );
Exception Type | Condition |
---|---|
ArgumentException | The source parameter does not exist in the registry of the local computer. |
ArgumentException | You do not have write access on the registry key for the event log. |
Use this overload to remove the registration of a Source from the local computer. DeleteEventSource accesses the registry on the local computer 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.
The following example closes an event log specified by the source "mySource", 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" 'Verify that the source exists. If EventLog.SourceExists(source) 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) End If End Sub
EventLog Class | EventLog Members | System.Diagnostics Namespace | EventLog.DeleteEventSource Overload List | CreateEventSource | Source | SourceExists | Delete | Clear