EventLog.Exists 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
判斷指定的對數是否存在。
多載
| 名稱 | Description |
|---|---|
| Exists(String) |
判斷該日誌是否存在於本地電腦。 |
| Exists(String, String) |
判斷該日誌是否存在於指定的電腦上。 |
Exists(String)
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
判斷該日誌是否存在於本地電腦。
public:
static bool Exists(System::String ^ logName);
public static bool Exists(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 或 value 是空的。
範例
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
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
- 來源:
- EventLog.cs
判斷該日誌是否存在於指定的電腦上。
public:
static bool Exists(System::String ^ logName, System::String ^ machineName);
public static bool Exists(string? logName, 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
例外狀況
備註
使用此方法判斷遠端電腦是否存在日誌。 如果你想判斷遠端電腦是否存在一個來源,請使用 SourceExists。
由於此方法會存取登錄檔,您必須在指定的電腦上擁有適當的登錄權限;否則,查詢會回傳 false。
因為你無法將同一台電腦上現有日誌的名稱給新日誌,請先用此方法來判斷該伺服器logName上是否machineName已存在該紀錄。
logName和 machineName 參數不區分大小寫。
Exists 是一個 static 方法,因此可以在類別本身上呼叫。 不必建立新的實例 EventLog 來呼叫 Exists。