EventLog.ModifyOverflowPolicy(OverflowAction, Int32) Método

Definição

Altera o comportamento configurado para gravar novas entradas quando o log de eventos atinge o tamanho máximo do arquivo.

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)

Parâmetros

action
OverflowAction

O comportamento de estouro para gravar novas entradas no log de eventos.

retentionDays
Int32

O número mínimo de dias durante os quais cada entrada de log de eventos é mantida. Este parâmetro será usado apenas se action for definido como OverwriteOlder.

Atributos

Exceções

action não é um valor OverflowAction válido.

retentionDays é menor do que um ou maior que 365.

O valor Log não é um nome de log válido.

- ou -

Não foi possível abrir a chave do Registro do log de eventos no computador de destino.

Exemplos

O exemplo a seguir exibe a política de estouro configurada para um log de eventos especificado e permite que o usuário selecione uma nova configuração de política de estouro para o log de eventos.

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

Comentários

O comportamento de estouro de um log de eventos especifica o que acontece quando novas entradas devem ser gravadas em um log que atingiu seu tamanho máximo de arquivo.

Observação

O comportamento de estouro entra em vigor somente quando um log de eventos atinge seu tamanho máximo de arquivo. O comportamento de estouro não afeta a gravação de uma nova entrada em um log que pode acomodar entradas de log de eventos adicionais.

O ModifyOverflowPolicy método configura o comportamento de estouro de um log de eventos. EventLog Instância. Depois de chamar esse método para o log de eventos especificado pela Log propriedade , os valores da OverflowAction propriedade e MinimumRetentionDays refletem o comportamento de estouro recém-configurado.

Observação

Essa propriedade representa uma definição de configuração para o log de eventos representado por essa instância. Quando o log de eventos atinge seu tamanho máximo, essa propriedade especifica como o sistema operacional lida com novas entradas gravadas por todas as fontes de eventos registradas para o log de eventos.

Defina o action parâmetro como OverwriteAsNeeded para indicar que uma nova entrada substitui a entrada mais antiga quando o EventLog atinge seu tamanho máximo. Se o action parâmetro for definido como OverwriteAsNeeded, o valor do retentionDays parâmetro será ignorado.

Defina o action parâmetro como OverwriteOlder para indicar que cada nova entrada substitui entradas mais antigas quando o EventLog atinge seu tamanho máximo. Especifique o número de dias que os eventos devem ser retidos no log usando o retentionDays parâmetro . Os eventos gravados dentro do intervalo de retenção não são substituídos por novas entradas.

Defina o action parâmetro como DoNotOverwrite para descartar novos eventos quando o tamanho máximo do log for atingido. Se o action parâmetro for definido como DoNotOverwrite, o valor do retentionDays parâmetro será ignorado.

Cuidado

Definir a política de estouro para DoNotOverwrite especifica que novas entradas são descartadas quando o log de eventos está cheio. Se você usar essa configuração, verifique se o log de eventos é arquivado e limpo regularmente para evitar atingir seu limite de tamanho máximo.

Aplica-se a

Confira também