संपादित करें

इसके माध्यम से साझा किया गया


EventLog.ModifyOverflowPolicy(OverflowAction, Int32) Method

Definition

Changes the configured behavior for writing new entries when the event log reaches its maximum file size.

public:
 void ModifyOverflowPolicy(System::Diagnostics::OverflowAction action, int retentionDays);
public void ModifyOverflowPolicy (System.Diagnostics.OverflowAction action, int retentionDays);
[System.Runtime.InteropServices.ComVisible(false)]
public void ModifyOverflowPolicy (System.Diagnostics.OverflowAction action, int retentionDays);
member this.ModifyOverflowPolicy : System.Diagnostics.OverflowAction * int -> unit
[<System.Runtime.InteropServices.ComVisible(false)>]
member this.ModifyOverflowPolicy : System.Diagnostics.OverflowAction * int -> unit
Public Sub ModifyOverflowPolicy (action As OverflowAction, retentionDays As Integer)

Parameters

action
OverflowAction

The overflow behavior for writing new entries to the event log.

retentionDays
Int32

The minimum number of days each event log entry is retained. This parameter is used only if action is set to OverwriteOlder.

Attributes

Exceptions

action is not a valid OverflowAction value.

retentionDays is less than one, or larger than 365.

The Log value is not a valid log name.

-or-

The registry key for the event log could not be opened on the target computer.

Examples

The following example displays the configured overflow policy for a specified event log, and allows the user to select a new overflow policy setting for the event log.

// Display the current event log overflow settings, and 
// prompt the user to input a new overflow setting.
void ChangeEventLogOverflowAction( String^ logName )
{
   if ( EventLog::Exists( logName ) )
   {
      
      // Display the current overflow setting of the 
      // specified event log.
      EventLog^ inputLog = gcnew EventLog( logName );
      Console::WriteLine( "  Event log {0}", inputLog->Log );
      OverflowAction logOverflow = inputLog->OverflowAction;
      Int32 numDays = inputLog->MinimumRetentionDays;
      Console::WriteLine( "  Current overflow setting = {0}", logOverflow );
      if ( logOverflow == OverflowAction::OverwriteOlder )
      {
         Console::WriteLine( "\t Entries are retained a minimum of {0} days.", numDays );
      }
      
      // Prompt user for a new overflow setting.
      GetNewOverflowSetting(  &logOverflow,  &numDays );
      
      // Change the overflow setting on the event log.
      if ( logOverflow != inputLog->OverflowAction )
      {
         inputLog->ModifyOverflowPolicy( logOverflow, numDays );
         Console::WriteLine( "Event log overflow policy was modified successfully!" );
      }
      else
      {
         Console::WriteLine( "Event log overflow policy was not modified." );
      }
   }
   else
   {
      Console::WriteLine( "Event log {0} was not found.", logName );
   }
}
// Display the current event log overflow settings, and
// prompt the user to input a new overflow setting.
public static void ChangeEventLogOverflowAction(String logName)
{
    if (EventLog.Exists(logName))
    {
        // Display the current overflow setting of the
        // specified event log.
        EventLog inputLog = new EventLog(logName);
        Console.WriteLine("  Event log {0}", inputLog.Log);

        OverflowAction logOverflow = inputLog.OverflowAction;
        Int32 numDays = inputLog.MinimumRetentionDays;

        Console.WriteLine("  Current overflow setting = {0}",
            logOverflow.ToString());
        if (logOverflow == OverflowAction.OverwriteOlder)
        {
            Console.WriteLine("\t Entries are retained a minimum of {0} days.",
                numDays.ToString());
        }

        // Prompt user for a new overflow setting.
        GetNewOverflowSetting(ref logOverflow, ref numDays);

        // Change the overflow setting on the event log.
        if (logOverflow != inputLog.OverflowAction)
        {
            inputLog.ModifyOverflowPolicy(logOverflow, numDays);
            Console.WriteLine("Event log overflow policy was modified successfully!");
        }
        else
        {
            Console.WriteLine("Event log overflow policy was not modified.");
        }
    }
    else
    {
        Console.WriteLine("Event log {0} was not found.", logName);
    }
}
 ' Display the current event log overflow settings, and 
 ' prompt the user to input a new overflow setting.
 Shared Sub ChangeEventLogOverflowAction(logName As String)

     If EventLog.Exists(logName) Then 
         Dim inputLog As EventLog = New EventLog(logName)
         Console.WriteLine("  Event log {0}", inputLog.Log)

         Dim logOverflow As OverflowAction = inputLog.OverflowAction
         Dim numDays As Int32 = inputLog.MinimumRetentionDays

         Console.WriteLine("  Current overflow setting = {0}", _
                           logOverflow.ToString())

         ' Prompt user for a new overflow setting.
         GetNewOverflowSetting(logOverflow, numDays)

         If Not logOverflow = inputLog.OverflowAction Then
             inputLog.ModifyOverflowPolicy(logOverflow, numDays)
             Console.WriteLine("Event log overflow policy was modified successfully!")
         Else
             Console.WriteLine("Event log overflow policy was not modified.")
         End If
         
     Else
         Console.WriteLine("Event log {0} was not found.", logName)
     End If

 End Sub

Remarks

The overflow behavior for an event log specifies what happens when new entries are to be written to a log that has reached its maximum file size.

Note

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 ModifyOverflowPolicy method configures the overflow behavior of an event log. EventLog instance. After calling this method for the event log specified by the Log property, the OverflowAction and MinimumRetentionDays property values reflect the newly configured overflow behavior.

Note

This property represents a configuration setting for the event log represented by this instance. When the event log reaches its maximum size, this property specifies how the operating system handles new entries written by all event sources registered for the event log.

Set the action parameter to OverwriteAsNeeded to indicate that a new entry overwrites the oldest entry when the EventLog reaches its maximum size. If the action parameter is set to OverwriteAsNeeded, the retentionDays parameter value is ignored.

Set the action parameter to OverwriteOlder to indicate that each new entry overwrites older entries when the EventLog reaches its maximum size. Specify the number of days that events must be retained in the log using the retentionDays parameter. Events written within the retention range are not overwritten by new entries.

Set the action parameter to DoNotOverwrite to discard new events when the maximum log size is reached. If the action parameter is set to DoNotOverwrite, the retentionDays parameter value is ignored.

Caution

Setting the overflow policy to DoNotOverwrite specifies that new entries are discarded when the event log is full. If you use this setting, ensure the event log is regularly archived and cleared to avoid reaching its maximum size limit.

Applies to

See also