Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
 EventLogEntryType Enumeration

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
EventLogEntryType Enumeration

Specifies the event type of an event log entry.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Enumeration EventLogEntryType
Visual Basic (Usage)
Dim instance As EventLogEntryType
C#
public enum EventLogEntryType
Visual C++
public enum class EventLogEntryType
JScript
public enum EventLogEntryType
Member nameDescription
Error An error event. This indicates a significant problem the user should know about; usually a loss of functionality or data.
Warning A warning event. This indicates a problem that is not immediately significant, but that may signify conditions that could cause future problems.
Information An information event. This indicates a significant, successful operation.
SuccessAudit A success audit event. This indicates a security event that occurs when an audited access attempt is successful; for example, logging on successfully.
FailureAudit A failure audit event. This indicates a security event that occurs when an audited access attempt fails; for example, a failed attempt to open a file.

The type of an event log entry provides additional information for the entry. Applications set the entry type when they write the entry to the event log.

Each event must be of a single type; the event types cannot be combined for an entry. The Event Viewer uses this type to determine which icon to display in the list view of the log.

The following code example demonstrates how to use the EventLogEntryType class to add information about triggered events to a log file. In this example, a switch statement is used to determine the event type. Each case statement uses the EventLogEntryType to specify the event type, gets the message and ID, and then writes the information to the log.

Visual Basic
' 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)

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

Visual C++
// 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 );


Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
PowerShell Eventing or How to have PowerShell write to the Eventlog / Event Log      LiveFromRaleigh   |   Edit   |   Show History

# For use with PowerShell v1.0
# Simply just not tested with PowerShell v2.0 - yet..... ;)
# Paste in to your code/script to add a event to Window's Event Log
# http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlog.writeentry.aspx


$PowerShell_Eventing=new-objectSystem.Diagnostics.EventLog("Application")

$PowerShell_Eventing.Source="Hello_World_CustomApp"

$Event_Type=[System.Diagnostics.EventLogEntryType]::Information

$PowerShell_Eventing.WriteEntry("Hello World token Text",$Event_Type,65000)

# or......

$PowerShell_Eventing=new-objectSystem.Diagnostics.EventLog("Application")

$PowerShell_Eventing.Source="Hello_World_Blah_Blah_App"

$Event_Type=[System.Diagnostics.EventLogEntryType]::Error

$PowerShell_Eventing.WriteEntry("Hello World - Error String Details of Blah, Blah",$Event_Type,65000)



Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker