Share via


How to: Remove an Event SourceĀ 

You can remove your source if you no longer need to use it to write entries to that log. Doing so affects all components that used that source to write to the log. For example, if you have two components that write to a log using the source string "mysource," removing "mysource" as a valid source of events affects both the components.

You might remove an event source if you were changing your source from one log to another. For example, suppose you want to stop writing entries to an OrdersProcessed log and start writing entries to an OrdersSent log. First, you would remove the association of the source with the first log, and then you would register the source with the new log to which you wanted to write events.

To remove an event source

  • Call the DeleteEventSource method, specifying the source name to remove.

    The following example shows how to unregister an event source named MyApp1 from the local computer. This code assumes that an Imports or using statement exists for the System.Diagnostics namespace:

    EventLog.DeleteEventSource("MyApp1")
    
    System.Diagnostics.EventLog.DeleteEventSource("MyApp1");
    
    System.Diagnostics.EventLog.DeleteEventSource("MyApp1");
    
    NoteTip

    To remove an event source from a remote computer, specify the computer name as a second parameter. The following code shows an example:

    EventLog.DeleteEventSource("MyApp1", "myserver")
    
    System.Diagnostics.EventLog.DeleteEventSource("MyApp1", "myserver");
    
    System.Diagnostics.EventLog.DeleteEventSource("MyApp1", "myserver");
    
    NoteNote

    Removing a source does not remove the entries that were written to that log using this source. However, it does affect the entries by adding information to them indicating that the source cannot be found.

See Also

Tasks

How to: Determine If an Event Source Exists
How to: Add Your Application as a Source of Event Log Entries
Walkthrough: Exploring Event Logs, Event Sources, and Entries