Export (0) Print
Expand All

EventLog.DeleteEventSource Method

Removes an application's event source registration from the event log.

Overload List

Removes the event source registration from the event log of the local computer.

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

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

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

Example

[Visual Basic, C#, C++] The following example deletes a source from the specified computer. The example determines the log from its source, and then deletes the log.

[Visual Basic, C#, C++] Note   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.
[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of DeleteEventSource. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
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

[C#] 
using System;
using System.Diagnostics;
using System.Threading;
              
class MySample{

    public static void Main(){

        string logName;
       
        if(EventLog.SourceExists("MyOldSource", "myServer")){
            logName = EventLog.LogNameFromSourceName("MyOldSource", "myServer");
            EventLog.DeleteEventSource("MyOldSource", "myServer");
            EventLog.Delete(logName, "myServer");
            
            Console.WriteLine(logName + " deleted.");     
        }                                                                     
    } 
}
   

[C++] 
#using <mscorlib.dll>
#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;

int main(){

    String* logName;

    if(EventLog::SourceExists(S"MyOldSource", S"myServer")){
        logName = EventLog::LogNameFromSourceName(S"MyOldSource", S"myServer");
        EventLog::DeleteEventSource(S"MyOldSource", S"myServer");
        EventLog::Delete(logName, S"myServer");

        Console::WriteLine(S"{0} deleted.", logName);     
    }                                                                     
} 

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

EventLog Class | EventLog Members | System.Diagnostics Namespace

Show:
© 2014 Microsoft