This documentation is archived and is not being maintained.

EventLog.Delete Method

Removes a log resource.

Overload List

Removes an event log from the local computer.

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

Removes an event log from the specified computer.

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

Example

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

[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 Delete. 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: