共用方式為


EventLogEntryType 列舉

定義

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

public enum class EventLogEntryType
public enum EventLogEntryType
type EventLogEntryType = 
Public Enum EventLogEntryType
繼承
EventLogEntryType

欄位

Error 1

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

FailureAudit 16

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

Information 4

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

SuccessAudit 8

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

Warning 2

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

範例

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

// Check whether source exist in event log.
if (  !EventLog::SourceExists( mySource ) )
{
   
   // Create a new source in a specified log on a system.
   EventLog::CreateEventSource( mySource, myLog );
}

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

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

備註

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

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

適用於

另請參閱