EventLog.DeleteEventSource Method (String, String)

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

Namespace: System.Diagnostics
Assembly: System (in system.dll)

Public Shared Sub DeleteEventSource ( _
	source As String, _
	machineName As String _
Dim source As String
Dim machineName As String

EventLog.DeleteEventSource(source, machineName)
public static void DeleteEventSource (
	String source, 
	String machineName
public static function DeleteEventSource (
	source : String, 
	machineName : String
Not applicable.



The name by which the application is registered in the event log system.


The name of the computer to remove the registration from, or "." for the local computer.

Exception typeCondition


The machineName parameter is invalid.

- or -

The source parameter does not exist in the registry of the specified computer.

- or -

You do not have write access on the registry key for the event log.


source cannot be deleted because in the registry, the parent registry key for source does not contain a subkey with the same name.

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 it to write entries to that log. For example, you might do this if you need to change your component from one log to another. Because a source can only be registered to one log at a time, changing the log requires you to remove 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 methods, so they can be called on the class itself. It is not necessary to create an instance of EventLog to call either method.

Deleting a log through a call to Delete automatically deletes the sources registered to that log. This can make other applications using that log inoperative.


If a source has already been mapped to a log and you remap it to a new log, you must restart the computer for the changes to take effect.

The following example deletes a source from the specified computer. The example determines the log from its source, and then deletes the log.


More than one source might write to an event log. Before deleting a custom log, make sure there are no other sources writing to that log.

Option Explicit
Option Strict

Imports System
Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        Dim logName As String
        If EventLog.SourceExists("MyOldSource", "myServer") Then
            logName = EventLog.LogNameFromSourceName("MyOldSource", "myServer")
            EventLog.DeleteEventSource("MyOldSource", "myServer")
            EventLog.Delete(logName, "myServer")
            Console.WriteLine((logName & " deleted."))
        End If
    End Sub 'Main
End Class 'MySample

import System.*;
import System.Diagnostics.*;
import System.Threading.*;

class MySample
    public static void main(String[] args)
        String logName;
        if (EventLog.SourceExists("MyOldSource", "myServer")) {
            logName = EventLog.LogNameFromSourceName("MyOldSource", 
            EventLog.DeleteEventSource("MyOldSource", "myServer");
            EventLog.Delete(logName, "myServer");
            Console.WriteLine(logName + " deleted.");
    } //main
} //MySample

Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0