EventLog.Exists Method

Definition

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

Overloads

Exists(String)

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

Exists(String, String)

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

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

Parameters

logName
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.

Returns

Boolean

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

Exceptions

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

Examples

      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

Remarks

使用這個方法來判斷本機電腦上是否存在記錄。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.

See also

Exists(String, String)

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

public:
 static bool Exists(System::String ^ logName, System::String ^ machineName);
public static bool Exists (string logName, 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

Parameters

logName
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

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

Returns

Boolean

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

Attributes

Exceptions

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.

Remarks

使用此方法來判斷遠端電腦上是否有記錄存在。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.

因為您無法在同一部電腦上提供現有記錄的名稱給新的記錄檔,請在建立新的記錄檔之前使用此方法,以判斷由 machineName 參數所指定的伺服器上是否已有指定的 logNameBecause 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.

See also

Applies to