EventLog.DeleteEventSource 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將應用程式的事件來源登錄從事件記錄檔移除。
多載
DeleteEventSource(String) |
將事件來源登錄從本機電腦的事件記錄檔移除。 |
DeleteEventSource(String, String) |
將應用程式的事件來源登錄從指定的電腦移除。 |
DeleteEventSource(String)
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- 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
應用程式在事件記錄檔系統中登錄的名稱。
例外狀況
範例
下列範例會從本機計算機刪除來源。 此範例會從其來源判斷記錄檔,然後刪除記錄檔。
注意
多個來源可能會寫入事件記錄檔。 刪除自訂記錄檔之前,請確定沒有其他來源寫入該記錄檔。
#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。 如果您只想要刪除記錄專案, 請呼叫 Clear。 Delete 和 DeleteEventSource 是 static
方法,因此可以在類別本身上呼叫它們。 不需要建立的 EventLog 實例來呼叫任一方法。
透過呼叫 刪除記錄檔,以 Delete 自動刪除註冊至該記錄的來源。 這可能會讓其他應用程式使用該登入。
注意
如果來源已經對應到記錄檔,而且您重新將它對應到新的記錄檔,您必須重新啟動計算機,變更才會生效。
另請參閱
適用於
DeleteEventSource(String, String)
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- 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
要移除登錄的電腦名稱,或者表示本機電腦的 "."。
例外狀況
無法刪除 source
,因為在登錄中,source
的父登錄機碼並未包含具有相同名稱的子機碼 (Subkey)。
範例
下列範例會從指定的計算機刪除來源。 此範例會從其來源判斷記錄檔,然後刪除記錄檔。
注意
多個來源可能會寫入事件記錄檔。 刪除自訂記錄檔之前,請確定沒有其他來源寫入該記錄檔。
#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。 如果您只想要刪除記錄專案, 請呼叫 Clear。 Delete 和 DeleteEventSource 是 static
方法,因此可以在類別本身上呼叫它們。 不需要建立的 EventLog 實例來呼叫任一方法。
透過呼叫 刪除記錄檔,以 Delete 自動刪除註冊至該記錄的來源。 這可能會讓其他應用程式使用該登入。
注意
如果來源已經對應到記錄檔,而且您重新將它對應到新的記錄檔,您必須重新啟動計算機,變更才會生效。