EventLog.ModifyOverflowPolicy(OverflowAction, Int32) Method

Definition

Cambia el comportamiento configurado para la escritura de entradas nuevas cuando el registro de eventos alcanza su tamaño máximo de archivo.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
Public Sub ModifyOverflowPolicy (action As OverflowAction, retentionDays As Integer)

Parameters

action
OverflowAction

Comportamiento de desbordamiento para la escritura de entradas nuevas en el registro de eventos.The overflow behavior for writing new entries to the event log.

retentionDays
Int32

Número mínimo de días que se conserva cada entrada del registro de eventos.The minimum number of days each event log entry is retained. Solo se utiliza este parámetro si action se establece en OverwriteOlder.This parameter is used only if action is set to OverwriteOlder.

Attributes

Exceptions

action no es un valor OverflowAction válido.action is not a valid OverflowAction value.

retentionDays es menor que 1 o mayor que 365.retentionDays is less than one, or larger than 365.

Log no es un nombre de registro válido.The Log value is not a valid log name.

O bien-or- No se ha podido abrir en el equipo de destino la clave del Registro para el registro de eventos.The registry key for the event log could not be opened on the target computer.

Examples

En el ejemplo siguiente se muestra la Directiva de desbordamiento configurada para un registro de eventos especificado y se permite que el usuario seleccione una nueva configuración de la Directiva de desbordamiento para el registro de eventos.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

El comportamiento de desbordamiento de un registro de eventos especifica lo que sucede cuando se escriben nuevas entradas en un registro que ha alcanzado su tamaño máximo de archivo.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

El comportamiento de desbordamiento solo surte efecto cuando un registro de eventos alcanza su tamaño máximo de archivo.The overflow behavior takes effect only when an event log reaches its maximum file size. El comportamiento de desbordamiento no afecta a la escritura de una entrada nueva en un registro que pueda contener entradas adicionales del registro de eventos.The overflow behavior does not affect writing a new entry to a log that can accommodate additional event log entries.

El método ModifyOverflowPolicy configura el comportamiento de desbordamiento de un registro de eventos.The ModifyOverflowPolicy method configures the overflow behavior of an event log. instancia de EventLog.EventLog instance. Después de llamar a este método para el registro de eventos especificado por la propiedad Log, los valores de propiedad OverflowAction y MinimumRetentionDays reflejan el comportamiento de desbordamiento recién configurado.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

Esta propiedad representa un valor de configuración para el registro de eventos representado por esta instancia.This property represents a configuration setting for the event log represented by this instance. Cuando el registro de eventos alcanza su tamaño máximo, esta propiedad especifica cómo el sistema operativo trata las nuevas entradas escritas por todos los orígenes de eventos registrados para el registro de eventos.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.

Establezca el parámetro action en OverwriteAsNeeded para indicar que una nueva entrada sobrescribe la entrada más antigua cuando el EventLog alcanza su tamaño máximo.Set the action parameter to OverwriteAsNeeded to indicate that a new entry overwrites the oldest entry when the EventLog reaches its maximum size. Si el parámetro action está establecido en OverwriteAsNeeded, se omite el valor del parámetro retentionDays.If the action parameter is set to OverwriteAsNeeded, the retentionDays parameter value is ignored.

Establezca el parámetro action en OverwriteOlder para indicar que cada nueva entrada sobrescribe las entradas más antiguas cuando el EventLog alcanza su tamaño máximo.Set the action parameter to OverwriteOlder to indicate that each new entry overwrites older entries when the EventLog reaches its maximum size. Especifique el número de días que se deben conservar los eventos en el registro mediante el parámetro retentionDays.Specify the number of days that events must be retained in the log using the retentionDays parameter. Los eventos escritos dentro de la duración de retención no se sobrescriben con las nuevas entradas.Events written within the retention range are not overwritten by new entries.

Establezca el parámetro action en DoNotOverwrite para descartar los nuevos eventos cuando se alcance el tamaño máximo del registro.Set the action parameter to DoNotOverwrite to discard new events when the maximum log size is reached. Si el parámetro action está establecido en DoNotOverwrite, se omite el valor del parámetro retentionDays.If the action parameter is set to DoNotOverwrite, the retentionDays parameter value is ignored.

Caution

Al establecer la Directiva de desbordamiento en DoNotOverwrite se especifica que las nuevas entradas se descartan cuando el registro de eventos está lleno.Setting the overflow policy to DoNotOverwrite specifies that new entries are discarded when the event log is full. Si utiliza esta configuración, asegúrese de que el registro de eventos se Archive y se borre periódicamente para evitar que se alcance el límite de tamaño máximo.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