EventLog.Exists 方法

定義

判斷指定的記錄檔是否存在。

多載

Exists(String)

判斷記錄檔是否存在於本機電腦上。

Exists(String, String)

判斷記錄檔是否存在於指定的電腦上。

Exists(String)

來源:
EventLog.cs
來源:
EventLog.cs
來源:
EventLog.cs

判斷記錄檔是否存在於本機電腦上。

public:
 static bool Exists(System::String ^ logName);
public static bool Exists (string logName);
static member Exists : string -> bool
Public Shared Function Exists (logName As String) As Boolean

參數

logName
String

要搜尋的記錄檔的名稱。 可能值包括:應用程式、安全性、系統、其他應用程式特定的記錄檔 (例如,與 Active Directory 關聯的記錄檔),或者電腦上的任何自訂記錄檔。

傳回

如果記錄檔存在於本機電腦上,則為 true,否則為 false

例外狀況

logName 是 null 或者是空值。

範例

      String^ myLog = "myNewLog";
      if ( EventLog::Exists( myLog ) )
      {
         Console::WriteLine( "Log '{0}' exists.", myLog );
      }
      else
      {
         Console::WriteLine( "Log '{0}' does not exist.", myLog );
      }
   }
   catch ( Exception^ e ) 
   {
      Console::WriteLine( "Exception: {0}", e->Message );
   }

}
string myLog = "myNewLog";
if (EventLog.Exists(myLog))
{
   Console.WriteLine("Log '"+myLog+"' exists.");
}
else
{
   Console.WriteLine("Log '"+myLog+"' does not exist.");
}
Dim myLog As String = "myNewLog"
If EventLog.Exists(myLog) Then
   Console.WriteLine("Log '" + myLog + "' exists.")
Else
   Console.WriteLine("Log '" + myLog + "' does not exist.")
End If

備註

使用這個方法來判斷本機計算機上是否存在記錄檔。 如果您要判斷來源是否存在於本機電腦上,請使用 SourceExists

因為這個方法會存取登錄,所以您必須在本機計算機上具有適當的登錄許可權;否則,查詢會傳 false回 。

因為您無法在相同計算機上為新的記錄提供現有記錄檔的名稱,所以在建立新的記錄檔之前,請先使用這個方法來判斷指定的 logName 是否已存在於本機計算機上。 參數 logName 不區分大小寫。

Exists 是方法 static ,因此可以在類別本身上呼叫。 不需要建立的 EventLog 實體來呼叫 Exists

另請參閱

適用於

Exists(String, String)

來源:
EventLog.cs
來源:
EventLog.cs
來源:
EventLog.cs

判斷記錄檔是否存在於指定的電腦上。

public:
 static bool Exists(System::String ^ logName, System::String ^ machineName);
public static bool Exists (string logName, string machineName);
static member Exists : string * string -> bool
Public Shared Function Exists (logName As String, machineName As String) As Boolean

參數

logName
String

要搜尋的記錄檔。 可能值包括:應用程式、安全性、系統、其他應用程式特定的記錄檔 (例如,與 Active Directory 關聯的記錄檔),或者電腦上的任何自訂記錄檔。

machineName
String

要在其上搜尋記錄檔的電腦的名稱,或者表示本機電腦的 "."。

傳回

如果記錄檔存在於指定的電腦上,則為 true;否則為 false

例外狀況

machineName 參數是無效的格式。 確認要搜尋的電腦採用的適合的語法。

-或-

logNamenull 或者是空值。

備註

使用這個方法來判斷遠端計算機上是否存在記錄檔。 如果您要判斷遠端電腦上是否存在來源,請使用 SourceExists

因為這個方法會存取登錄,所以您必須在指定的計算機上擁有適當的登錄許可權;否則,查詢會傳 false回 。

因為您無法在相同計算機上為新的記錄提供現有記錄檔的名稱,所以在建立新的記錄檔之前,請先使用這個方法來判斷參數所machineName指定伺服器上是否有具有指定logName之 的記錄檔。 logNamemachineName 參數不區分大小寫。

Exists 是方法 static ,因此可以在類別本身上呼叫。 不需要建立 的新實體來 EventLog 呼叫 Exists

另請參閱

適用於