EventLog.Exists EventLog.Exists EventLog.Exists EventLog.Exists Method

定義

判斷指定的記錄檔是否存在。Determines whether the specified log exists.

多載

Exists(String) Exists(String) Exists(String) Exists(String)

判斷記錄檔是否存在於本機電腦上。Determines whether the log exists on the local computer.

Exists(String, String) Exists(String, String) Exists(String, String) Exists(String, String)

判斷記錄檔是否存在於指定的電腦上。Determines whether the log exists on the specified computer.

Exists(String) Exists(String) Exists(String) Exists(String)

判斷記錄檔是否存在於本機電腦上。Determines whether the log exists on the local computer.

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 String String String

要搜尋的記錄檔的名稱。The name of the log to search for. 可能的值包括:應用程式、安全性、系統、其他應用程式特定的記錄檔 (例如,與 Active Directory 建立關聯的記錄檔),或電腦上的任何自訂記錄檔。Possible values include: Application, Security, System, other application-specific logs (such as those associated with Active Directory), or any custom log on the computer.

傳回

如果記錄檔存在於本機電腦上,則為 true,否則為 falsetrue if the log exists on the local computer; otherwise, false.

例外狀況

logName 是 null 或者是空值。The logName is null or the value is empty.

範例

      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

備註

使用此方法來判斷是否記錄檔存在於本機電腦上。Use this method to determine if a log exists on the local computer. 如果您想要判斷來源是否存在於本機電腦,也就是使用SourceExistsIf you want to determine whether a source exists on the local computer, use SourceExists.

由於這個方法會存取登錄,您還必須擁有適當的登錄權限,本機電腦上,否則,查詢會傳回falseBecause this method accesses the registry, you must have the appropriate registry permissions on the local computer; otherwise, the query returns false.

是因為您無法在相同電腦上讓新的記錄檔的現有記錄檔名稱,然後再建立新的記錄檔使用此方法來判斷是否指定logName已存在於本機電腦上。Because you cannot give a new log the name of an existing log on the same computer, use this method before creating a new log to determine if the specified logName already exists on the local computer. logName參數不區分大小寫。The logName parameter is not case sensitive.

Existsstatic方法,所以它可以呼叫類別本身。Exists is a static method, so it can be called on the class itself. 您不需要建立的執行個體EventLog呼叫ExistsIt is not necessary to create an instance of EventLog to call Exists.

安全性

EventLogPermission
用於管理的電腦上的事件記錄檔資訊。for administering event log information on the computer. 相關聯的列舉型別: AdministerAssociated enumeration: Administer

另請參閱

Exists(String, String) Exists(String, String) Exists(String, String) Exists(String, String)

判斷記錄檔是否存在於指定的電腦上。Determines whether the log exists on the specified computer.

public:
 static bool Exists(System::String ^ logName, System::String ^ machineName);
[System.MonoNotSupported("remote machine is not supported")]
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 String String String

要搜尋的記錄檔。The log for which to search. 可能的值包括:應用程式、安全性、系統、其他應用程式特定的記錄檔 (例如,與 Active Directory 建立關聯的記錄檔),或電腦上的任何自訂記錄檔。Possible values include: Application, Security, System, other application-specific logs (such as those associated with Active Directory), or any custom log on the computer.

machineName
String String String String

要在其上搜尋記錄檔的電腦的名稱,或者表示本機電腦的 "."。The name of the computer on which to search for the log, or "." for the local computer.

傳回

如果記錄檔存在於指定的電腦上,則為 true;否則為 falsetrue if the log exists on the specified computer; otherwise, false.

例外狀況

machineName 參數是無效的格式。The machineName parameter is an invalid format. 確認要搜尋的電腦採用的適合的語法。Make sure you have used proper syntax for the computer on which you are searching.

-或--or- logNamenull 或者是空值。The logName is null or the value is empty.

備註

使用此方法來判斷遠端電腦上是否有記錄檔。Use this method to determine if a log exists on a remote computer. 如果您想要判斷來源是否存在的遠端電腦上,使用SourceExistsIf you want to determine whether a source exists on a remote computer, use SourceExists.

由於這個方法會存取登錄,您必須擁有適當的登錄權限指定電腦上,否則,查詢會傳回falseBecause this method accesses the registry, you must have the appropriate registry permissions on the specified computer; otherwise, the query returns false.

是因為您無法在相同電腦上讓新的記錄檔的現有記錄檔名稱,然後再建立新的記錄檔使用此方法以判斷是一個具有指定之logName已存在於所指定的伺服器上machineName參數。Because you cannot give a new log the name of an existing log on the same computer, use this method before creating a new log to determine if one with the specified logName already exists on the server specified by the machineName parameter. logNamemachineName參數不區分大小寫。The logName and machineName parameters are not case sensitive.

Existsstatic方法,所以它可以呼叫類別本身。Exists is a static method, so it can be called on the class itself. 您不需要建立的新執行個體EventLog呼叫ExistsIt is not necessary to create a new instance of EventLog to call Exists.

安全性

EventLogPermission
用於管理的電腦上的事件記錄檔資訊。for administering event log information on the computer. 相關聯的列舉型別: AdministerAssociated enumeration: Administer

另請參閱

適用於