EventLog.Exists 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
确定指定的日志是否存在。
重载
| 名称 | 说明 |
|---|---|
| Exists(String) |
确定本地计算机上是否存在日志。 |
| Exists(String, String) |
确定日志是否存在于指定的计算机上。 |
Exists(String)
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- 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 或值为空。
示例
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)
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- EventLog.cs
- Source:
- 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 日志。 参数logNamemachineName不区分大小写。
Exists 是一个 static 方法,因此可以在类本身上调用该方法。 不需要创建要调用EventLog的新实例Exists。