EventLog.DeleteEventSource 方法
定义
从事件日志中移除应用程序的事件源注册。Removes an application's event source registration from the event log.
重载
| DeleteEventSource(String) |
从本地计算机的事件日志中移除事件源注册。Removes the event source registration from the event log of the local computer. |
| DeleteEventSource(String, String) |
从指定的计算机上移除应用程序的事件源注册。Removes the application's event source registration from the specified computer. |
DeleteEventSource(String)
从本地计算机的事件日志中移除事件源注册。Removes the event source registration from the event log of the local computer.
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
应用程序在事件日志系统中用来注册的名称。The name by which the application is registered in the event log system.
例外
本地计算机的注册表中不存在 source 参数。The source parameter does not exist in the registry of the local computer.
- 或 --or- 您对事件日志的注册表项没有写访问权。You do not have write access on the registry key for the event log.
示例
以下示例从本地计算机中删除源。The following example deletes a source from the local 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.
#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 MySample
{
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 从本地计算机删除注册。Use this method to remove the registration of a Source from the local computer. DeleteEventSource 访问本地计算机上的注册表,并将应用程序注册为事件的有效源。DeleteEventSource accesses the registry on the local computer 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 仅删除注册到日志的源。DeleteEventSource removes only the source registered to a log. 如果要删除日志本身,请调用 Delete 。If you want to remove the log itself, call Delete. 如果只想删除日志条目,请调用 Clear 。If you only want to delete the log entries, call Clear. Delete 和 DeleteEventSource 是 static 方法,因此它们可以在类本身上调用。Delete and DeleteEventSource are static methods, so they can be called on the class itself. 不需要创建的实例 EventLog 来调用这两种方法。It is not necessary to create an instance of EventLog to call either method.
通过对的调用删除日志 Delete 会自动删除注册到该日志的源。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.
另请参阅
适用于
DeleteEventSource(String, String)
从指定的计算机上移除应用程序的事件源注册。Removes the application's event source registration from the specified computer.
public:
static void DeleteEventSource(System::String ^ source, System::String ^ machineName);
public static void DeleteEventSource (string source, string machineName);
[System.MonoNotSupported("remote machine is not supported")]
public static void DeleteEventSource (string source, string machineName);
static member DeleteEventSource : string * string -> unit
[<System.MonoNotSupported("remote machine is not supported")>]
static member DeleteEventSource : string * string -> unit
Public Shared Sub DeleteEventSource (source As String, machineName As String)
参数
- source
- String
应用程序在事件日志系统中用来注册的名称。The name by which the application is registered in the event log system.
- machineName
- String
要从中移除注册的计算机名,对于本地计算机则为“.”。The name of the computer to remove the registration from, or "." for the local computer.
- 属性
-
MonoNotSupportedAttribute
例外
machineName 参数无效。The machineName parameter is invalid.
- 或 --or-
指定计算机的注册表中不存在 source 参数。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,原因是在注册表中,source 的父注册表项不包含与其同名的子项。source cannot be deleted because in the registry, the parent registry key for source does not contain a subkey with the same name.
示例
以下示例从指定的计算机中删除源。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.
#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 从远程计算机中删除的注册。Use this overload to remove the registration of a Source from a remote computer. DeleteEventSource 访问由指定的计算机上的注册表 machineName ,并将应用程序注册为事件的有效源。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 仅删除注册到日志的源。DeleteEventSource removes only the source registered to a log. 如果要删除日志本身,请调用 Delete 。If you want to remove the log itself, call Delete. 如果只想删除日志条目,请调用 Clear 。If you only want to delete the log entries, call Clear. Delete 和 DeleteEventSource 是 static 方法,因此它们可以在类本身上调用。Delete and DeleteEventSource are static methods, so they can be called on the class itself. 不需要创建的实例 EventLog 来调用这两种方法。It is not necessary to create an instance of EventLog to call either method.
通过对的调用删除日志 Delete 会自动删除注册到该日志的源。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.