EventLog.DeleteEventSource 方法

定义

从事件日志中移除应用程序的事件源注册。

重载

DeleteEventSource(String)

从本地计算机的事件日志中移除事件源注册。

DeleteEventSource(String, String)

从指定的计算机上移除应用程序的事件源注册。

DeleteEventSource(String)

Source:
EventLog.cs
Source:
EventLog.cs
Source:
EventLog.cs

从本地计算机的事件日志中移除事件源注册。

public:
 static void DeleteEventSource(System::String ^ source);
public static void DeleteEventSource (string source);
static member DeleteEventSource : string -> unit
Public Shared Sub DeleteEventSource (source As String)

参数

source
String

应用程序在事件日志系统中用来注册的名称。

例外

本地计算机的注册表中不存在 source 参数。

- 或 -

您对事件日志的注册表项没有写访问权。

示例

以下示例从本地计算机中删除源。 该示例从其源中确定日志,然后删除该日志。

注意

多个源可能会写入事件日志。 删除自定义日志之前,请确保没有其他源写入该日志。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   String^ logName;
   if ( EventLog::SourceExists( "MySource" ) )
   {
      
      // Find the log associated with this source.    
      logName = EventLog::LogNameFromSourceName( "MySource", "." );
      // Make sure the source is in the log we believe it to be in
      if (logName != "MyLog")
          return -1;
      // Delete the source and the log.
      EventLog::DeleteEventSource( "MySource" );
      EventLog::Delete( logName );
      Console::WriteLine( "{0} deleted.", logName );
   }
   else
        {
            // Create the event source to make next try successful.
            EventLog::CreateEventSource("MySource", "MyLog");
        }
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample1
{
    public static void Main()
    {
        string logName;

        if (EventLog.SourceExists("MySource"))
        {
            // Find the log associated with this source.
            logName = EventLog.LogNameFromSourceName("MySource", ".");
            // Make sure the source is in the log we believe it to be in.
            if (logName != "MyLog")
                return;
            // Delete the source and the log.
            EventLog.DeleteEventSource("MySource");
            EventLog.Delete(logName);

            Console.WriteLine(logName + " deleted.");
        }
        else
        {
            // Create the event source to make next try successful.
            EventLog.CreateEventSource("MySource", "MyLog");
        }
    }
}
Option Explicit On
Option Strict On

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        Dim logName As String

        If EventLog.SourceExists("MySource") Then
            ' Find the log associated with this source.    
            logName = EventLog.LogNameFromSourceName("MySource", ".")
            ' Make sure the source is in the log we believe it to be in
            If (logName <> "MyLog") Then
                Return
            End If
            ' Delete the source and the log.
            EventLog.DeleteEventSource("MySource")
            EventLog.Delete(logName)

            Console.WriteLine((logName & " deleted."))
        Else
            ' Create the event source to make next try successful.
            EventLog.CreateEventSource("MySource", "MyLog")
        End If
    End Sub
End Class

注解

使用此方法从本地计算机中删除 的 Source 注册。 DeleteEventSource 访问本地计算机上的注册表,并删除应用程序作为有效事件源的注册。

如果不再需要组件将条目写入该日志,则可以将其删除为事件的有效源。 例如,如果需要将组件从一个日志更改为另一个日志,则可以执行此操作。 由于源一次只能注册到一个日志,因此更改日志需要删除当前注册。

DeleteEventSource 仅删除注册到日志的源。 如果要删除日志本身,请调用 Delete。 如果只想删除日志条目,请调用 ClearDeleteDeleteEventSourcestatic 方法,因此可以在类本身上调用它们。 无需创建 实例来调用任一 EventLog 方法。

通过调用 Delete 删除日志会自动删除注册到该日志的源。 这会使使用该日志的其他应用程序无法运行。

注意

如果源已映射到日志,并且你将其重新映射到新日志,则必须重新启动计算机才能使更改生效。

另请参阅

适用于

DeleteEventSource(String, String)

Source:
EventLog.cs
Source:
EventLog.cs
Source:
EventLog.cs

从指定的计算机上移除应用程序的事件源注册。

public:
 static void DeleteEventSource(System::String ^ source, System::String ^ machineName);
public static void DeleteEventSource (string source, string machineName);
static member DeleteEventSource : string * string -> unit
Public Shared Sub DeleteEventSource (source As String, machineName As String)

参数

source
String

应用程序在事件日志系统中用来注册的名称。

machineName
String

要从中移除注册的计算机名,对于本地计算机则为“.”。

例外

machineName 参数无效。

- 或 -

指定计算机的注册表中不存在 source 参数。

- 或 -

您对事件日志的注册表项没有写访问权。

无法删除 source,原因是在注册表中,source 的父注册表项不包含与其同名的子项。

示例

以下示例从指定计算机中删除源。 该示例从其源中确定日志,然后删除该日志。

注意

多个源可能会写入事件日志。 删除自定义日志之前,请确保没有其他源写入该日志。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::Threading;
int main()
{
   String^ logName;
   if ( EventLog::SourceExists( "MySource", "MyMachine") )
   {
      
      // Find the log associated with this source.    
      logName = EventLog::LogNameFromSourceName( "MySource", "MyMachine" );
      // Make sure the source is in the log we believe it to be in
      if (logName != "MyLog")
          return -1;
      // Delete the source and the log.
      EventLog::DeleteEventSource( "MySource", "MyMachine" );
      EventLog::Delete( logName, "MyMachine" );
      Console::WriteLine( "{0} deleted.", logName );
   }
   else
        {
            // Create the event source to make next try successful.
            EventSourceCreationData^ mySourceData = gcnew EventSourceCreationData("MySource", "MyLog");
            mySourceData->MachineName = "MyMachine";
            EventLog::CreateEventSource(mySourceData);
        }
}
using System;
using System.Diagnostics;
using System.Threading;

class MySample
{
    public static void Main()
    {
        string logName;

        if (EventLog.SourceExists("MySource", "MyMachine"))
        {
            // Find the log associated with this source.
            logName = EventLog.LogNameFromSourceName("MySource", "MyMachine");
            // Make sure the source is in the log we believe it to be in.
            if (logName != "MyLog")
                return;
            // Delete the source and the log.
            EventLog.DeleteEventSource("MySource", "MyMachine");
            EventLog.Delete(logName, "MyMachine");

            Console.WriteLine(logName + " deleted.");
        }
        else
        {
            // Create the event source to make next try successful.
            EventSourceCreationData mySourceData = new EventSourceCreationData("MySource", "MyLog");
            mySourceData.MachineName = "MyMachine";
            EventLog.CreateEventSource(mySourceData);
        }
    }
}
Option Explicit On
Option Strict On

Imports System.Diagnostics
Imports System.Threading

Class MySample
    Public Shared Sub Main()
        Dim logName As String

        If EventLog.SourceExists("MySource", "MyMachine") Then
            ' Find the log associated with this source.    
            logName = EventLog.LogNameFromSourceName("MySource", "MyMachine")
            ' Make sure the source is in the log we believe it to be in
            If (logName <> "MyLog") Then
                Return
            End If
            ' Delete the source and the log.
            EventLog.DeleteEventSource("MySource", "MyMachine")
            EventLog.Delete(logName, "MyMachine")

            Console.WriteLine((logName & " deleted."))
        Else
            ' Create the event source to make next try successful.
            Dim mySourceData As New EventSourceCreationData("MySource", "MyLog")
            mySourceData.MachineName = "MyMachine"
            EventLog.CreateEventSource(mySourceData)
        End If
    End Sub
End Class

注解

使用此重载从远程计算机中删除 的 Source 注册。 DeleteEventSource 访问由 machineName 指定的计算机上的注册表,并删除应用程序作为有效事件源的注册。

如果不再需要组件将条目写入该日志,则可以将其删除为事件的有效源。 例如,如果需要将组件从一个日志更改为另一个日志,则可以执行此操作。 由于源一次只能注册到一个日志,因此更改日志需要删除当前注册。

DeleteEventSource 仅删除注册到日志的源。 如果要删除日志本身,请调用 Delete。 如果只想删除日志条目,请调用 ClearDeleteDeleteEventSourcestatic 方法,因此可以在类本身上调用它们。 无需创建 实例来调用任一 EventLog 方法。

通过调用 Delete 删除日志会自动删除注册到该日志的源。 这会使使用该日志的其他应用程序无法运行。

注意

如果源已映射到日志,并且你将其重新映射到新日志,则必须重新启动计算机才能使更改生效。

另请参阅

适用于