EventLog.ModifyOverflowPolicy(OverflowAction, Int32) EventLog.ModifyOverflowPolicy(OverflowAction, Int32) EventLog.ModifyOverflowPolicy(OverflowAction, Int32) EventLog.ModifyOverflowPolicy(OverflowAction, Int32) Method

定義

當事件記錄檔到達最大檔案大小時,變更寫入新項目的已設定行為。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);
[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)

參數

action
OverflowAction OverflowAction OverflowAction OverflowAction

將新的項目寫入事件記錄檔的溢位行為。The overflow behavior for writing new entries to the event log.

retentionDays
Int32 Int32 Int32 Int32

每一個事件記錄檔項目會保留的最小天數。The minimum number of days each event log entry is retained. 只有當 action 設定為 OverwriteOlder 時,才會使用這個參數。This parameter is used only if action is set to OverwriteOlder.

例外狀況

retentionDays 小於 1 或大於 365。retentionDays is less than one, or larger than 365.

這個 Log 值不是有效的記錄檔名稱。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.

範例

下列範例顯示針對指定的事件記錄檔中,已設定的溢位原則,並允許使用者選取新的溢位原則設定事件記錄檔。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

備註

事件記錄檔的溢位行為會指定要寫入的記錄檔已達到其最大檔案大小,新的項目時,會發生什麼事。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.

注意

溢位行為在事件記錄檔達到檔案大小上限時,才會生效。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.

ModifyOverflowPolicy方法則會設定事件記錄檔的溢位行為。The ModifyOverflowPolicy method configures the overflow behavior of an event log. EventLog 執行個體。EventLog instance. 呼叫這個方法所指定的事件記錄檔之後Log屬性,OverflowActionMinimumRetentionDays屬性的值反映的新設定的溢位行為。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.

注意

這個屬性表示此執行個體所代表的事件記錄檔的組態設定。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.

設定action參數來OverwriteAsNeeded表示,新的項目會覆寫舊的項目時EventLog達到最大值。Set the action parameter to OverwriteAsNeeded to indicate that a new entry overwrites the oldest entry when the EventLog reaches its maximum size. 如果action參數設定為OverwriteAsNeeded,則retentionDays參數值會被忽略。If the action parameter is set to OverwriteAsNeeded, the retentionDays parameter value is ignored.

設定action參數來OverwriteOlder表示,每個新的項目會覆寫較舊的項目時EventLog達到最大值。Set the action parameter to OverwriteOlder to indicate that each new entry overwrites older entries when the EventLog reaches its maximum size. 指定在記錄檔中使用的事件必須保留的天數retentionDays參數。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.

設定action參數來DoNotOverwrite捨棄新的事件,當達到最大記錄大小。Set the action parameter to DoNotOverwrite to discard new events when the maximum log size is reached. 如果action參數設定為DoNotOverwrite,則retentionDays參數值會被忽略。If the action parameter is set to DoNotOverwrite, the retentionDays parameter value is ignored.

警告

將溢位的原則設定為DoNotOverwrite指定事件記錄檔已滿時,就會捨棄新的項目。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.

安全性

EventLogPermission
用於管理的電腦上的事件記錄檔資訊。for administering event log information on the computer. 相關聯的列舉型別: AdministerAssociated enumeration: Administer

適用於

另請參閱