OverflowAction Property

EventLog.OverflowAction Property

Gets the configured behavior for storing new entries when the event log reaches its maximum log file size.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)

<BrowsableAttribute(False)> _
<ComVisibleAttribute(False)> _
Public ReadOnly Property OverflowAction As OverflowAction
Dim instance As EventLog 
Dim value As OverflowAction 

value = instance.OverflowAction

Property Value

Type: System.Diagnostics.OverflowAction
The OverflowAction value that specifies the configured behavior for storing new entries when the event log reaches its maximum log size. The default is OverwriteOlder.

Event logs grow in size as new events are written to them. Each event log has a configured maximum size limit; the MaximumKilobytes property defines the maximum number of kilobytes allowed for the event log file size.

Use the OverflowAction property value to examine the configured overflow behavior for an event log at its maximum size. Use the ModifyOverflowPolicy method to change the overflow behavior for an event log.


The overflow behavior takes effect only when an event log reaches its maximum file size. The overflow behavior does not affect writing a new entry to a log that can accommodate additional event log entries.

The following example enumerates the event logs defined on the local computer, and displays configuration details for each event log.

Shared Sub DisplayEventLogProperties()

   ' Iterate through the current set of event log files, 
   ' displaying the property settings for each file. 
   Dim eventLogs As EventLog() = EventLog.GetEventLogs()

   Dim e As EventLog
   For Each e In  eventLogs
      Dim sizeKB As Int64 = 0

      Console.WriteLine("{0}:", e.LogDisplayName)
      Console.WriteLine("  Log name = " + ControlChars.Tab _
                          + ControlChars.Tab + " {0}", e.Log)

      Console.WriteLine("  Number of event log entries = {0}", e.Entries.Count.ToString())

      ' Determine if there is an event log file for this event log. 
      Dim regEventLog As RegistryKey
      regEventLog = Registry.LocalMachine.OpenSubKey( _
             ("System\CurrentControlSet\Services\EventLog\" + e.Log))

      If Not (regEventLog Is Nothing) Then 

         Dim temp As Object = regEventLog.GetValue("File")
         If Not (temp Is Nothing) Then

            Console.WriteLine("  Log file path = " + ControlChars.Tab _
                                  + " {0}", temp.ToString())
            Dim file As New FileInfo(temp.ToString())

            ' Get the current size of the event log file. 
            If file.Exists Then
               sizeKB = file.Length / 1024
               If file.Length Mod 1024 <> 0 Then
                  sizeKB += 1
               End If
               Console.WriteLine("  Current size = " + ControlChars.Tab _
                          + " {0} kilobytes", sizeKB.ToString())
            End If 
            Console.WriteLine("  Log file path = " + ControlChars.Tab _
                             + " <not set>")
         End If 
      End If 

      ' Display the maximum size and overflow settings.
      sizeKB = e.MaximumKilobytes
      Console.WriteLine("  Maximum size = " + ControlChars.Tab _
                         + " {0} kilobytes", sizeKB.ToString())
      Console.WriteLine("  Overflow setting = " + ControlChars.Tab _
                         + " {0}", e.OverflowAction.ToString())

      Select Case e.OverflowAction
         Case OverflowAction.OverwriteOlder
            Console.WriteLine(ControlChars.Tab + _
                 " Entries are retained a minimum of {0} days.", _
         Case OverflowAction.DoNotOverwrite
            Console.WriteLine(ControlChars.Tab + _
                 " Older entries are not overwritten.")
         Case OverflowAction.OverwriteAsNeeded
            Console.WriteLine(ControlChars.Tab + _
                 " If number of entries equals max size limit, a new event log entry overwrites the oldest entry.")
         Case Else 
      End Select 

   Next e

End Sub

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

Community Additions

© 2015 Microsoft