EventLogEntryType 列舉

定義

指定事件記錄檔項目的事件型別。

C#
public enum EventLogEntryType
繼承
EventLogEntryType

欄位

名稱 Description
Error 1

錯誤事件。 這表示是使用者應該知道的重要問題,通常是功能或資料的遺失。

FailureAudit 16

失敗稽核事件。 這表示受稽核的存取嘗試失敗時發生的安全性事件,例如無法開啟檔案。

Information 4

資訊事件。 這表示重要成功的作業。

SuccessAudit 8

成功稽核事件。 這表示受稽核存取嘗試成功時所發生的安全性事件,例如登錄成功。

Warning 2

警告事件。 這表示不是立即重要的問題,但是可能表示將來會引發問題的狀況。

範例

下列程式代碼範例示範如何使用 EventLogEntryType 類別,將觸發事件的相關信息新增至記錄檔。 在此範例中 switch ,語句是用來判斷事件類型。 每個 case 語句都會使用 EventLogEntryType 來指定事件類型、取得訊息和標識碼,然後將資訊寫入記錄檔。

C#

// 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);

備註

事件記錄檔項目的類型會提供專案的其他資訊。 當應用程式將專案寫入事件記錄檔時,會設定項目類型。

每個事件都必須是單一類型;無法合併專案的事件類型。 事件檢視器會使用這個型別判斷要在記錄檔的清單檢視中顯示哪個圖示。

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱