EventLogEntryType 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定事件記錄檔專案的事件類型。
public enum class EventLogEntryType
public enum EventLogEntryType
type EventLogEntryType =
Public Enum EventLogEntryType
- 繼承
欄位
| 名稱 | 值 | Description |
|---|---|---|
| Error | 1 | 錯誤事件。 這表示使用者應該知道一個重大問題;通常是功能或資料的損失。 |
| Warning | 2 | 一個警告事件。 這表示問題並非立即嚴重,但可能代表未來可能出現的問題。 |
| Information | 4 | 一場資訊活動。 這顯示出一場重要且成功的行動。 |
| SuccessAudit | 8 | 一個成功的稽核活動。 這表示當經稽核的存取嘗試成功時會發生安全事件;例如,成功登入。 |
| FailureAudit | 16 | 一個失敗稽核事件。 這表示當經稽核的存取嘗試失敗時,會發生安全事件;例如,嘗試開啟檔案失敗。 |
範例
以下程式碼範例示範如何利用該 EventLogEntryType 類別將觸發事件的資訊加入日誌檔案。 在此範例中,使用一個 switch 陳述來決定事件類型。 每個 case 語句使用 來 EventLogEntryType 指定事件類型,取得訊息和 ID,然後將資訊寫入日誌。
// Create an event log instance.
myEventLog = new EventLog(myLog);
// Initialize source property of obtained instance.
myEventLog.Source = mySource;
switch (myIntLog)
{
case 1:
// Write an 'Error' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.Error, myID);
break;
case 2:
// Write a 'Warning' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.Warning, myID);
break;
case 3:
// Write an 'Information' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.Information, myID);
break;
case 4:
// Write a 'FailureAudit' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.FailureAudit, myID);
break;
case 5:
// Write a 'SuccessAudit' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.SuccessAudit, myID);
break;
default:
Console.WriteLine("Error: Failed to create an event in event log.");
break;
}
Console.WriteLine("A new event in log '{0}' with ID '{1}' "
+ "is successfully written into event log.",
myEventLog.Log, myID);
' Check whether source exist in event log.
If False = EventLog.SourceExists(mySource) Then
' Create a new source in a specified log on a system.
EventLog.CreateEventSource(mySource, myLog)
End If
' Create an event log instance.
myEventLog = New EventLog(myLog)
' Initialize source property of obtained instance.
myEventLog.Source = mySource
Select Case myIntLog
Case 1
' Write an 'Error' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.Error, myID)
Case 2
' Write a 'Warning' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.Warning, myID)
Case 3
' Write an 'Information' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.Information, myID)
Case 4
' Write a 'FailureAudit' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.FailureAudit, myID)
Case 5
' Write a 'SuccessAudit' entry in specified log of event log.
myEventLog.WriteEntry(myMessage, EventLogEntryType.SuccessAudit, myID)
Case Else
Console.WriteLine("Error: Failed to create an event in event log.")
End Select
Console.WriteLine("A new event in log '{0}' with ID '{1}' " + _
"is successfully written into event log.", myEventLog.Log, myID)
備註
事件日誌條目的類型會提供該條目的額外資訊。 應用程式在寫入事件日誌時會設定該條目類型。
每個事件必須屬於單一類型;活動類型無法合併作為參賽作品。 事件檢視器 使用此類型來決定在日誌清單檢視中顯示哪個圖示。