EventLog.ModifyOverflowPolicy(OverflowAction, Int32) 方法

定義

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

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

retentionDays
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.

屬性

例外狀況

action 不是有效的 OverflowAction 值。action is not a valid OverflowAction value.

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

適用於

另請參閱