共用方式為


EventLog.ModifyOverflowPolicy(OverflowAction, Int32) 方法

定義

當事件記錄檔到達最大檔案大小時,變更寫入新項目的已設定行為。

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)

參數

action
OverflowAction

將新的項目寫入事件記錄檔的溢位行為。

retentionDays
Int32

每一個事件記錄檔項目會保留的最小天數。 只有當 action 設定為 OverwriteOlder 時,才會使用這個參數。

屬性

例外狀況

action 不是有效的 OverflowAction 值。

retentionDays 小於 1 或大於 365。

這個 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

備註

事件記錄檔的溢位行為會指定將新專案寫入已達到檔案大小上限的記錄檔時,會發生什麼情況。

注意

只有在事件記錄檔達到檔案大小上限時,溢位行為才會生效。 溢位行為不會影響將新專案寫入可容納其他事件記錄檔項目的記錄檔。

方法 ModifyOverflowPolicy 會設定事件記錄檔的溢位行為。 EventLog 實例。 針對屬性所 Log 指定的事件記錄檔呼叫這個方法之後, OverflowActionMinimumRetentionDays 屬性值會反映新設定的溢位行為。

注意

這個屬性代表這個實例所表示之事件記錄檔的組態設定。 當事件記錄檔達到其大小上限時,此屬性會指定操作系統如何處理針對事件記錄檔註冊的所有事件來源所寫入的新專案。

action 參數設定為 OverwriteAsNeeded ,表示當達到最大大小時 EventLog ,新專案會覆寫最舊的專案。 action如果參數設定為 OverwriteAsNeeded,則會retentionDays忽略參數值。

action將 參數設定為 OverwriteOlder ,表示當 達到其大小上限時EventLog,每個新專案都會覆寫較舊的專案。 使用 retentionDays 參數,指定事件必須保留在記錄中的天數。 新專案不會覆寫在保留範圍內寫入的事件。

action 參數設定為 DoNotOverwrite ,以在達到記錄大小上限時捨棄新事件。 action如果參數設定為 DoNotOverwrite,則會retentionDays忽略參數值。

警告

將溢位原則設定為 DoNotOverwrite ,指定當事件記錄檔已滿時,會捨棄新專案。 如果您使用此設定,請確定事件記錄檔會定期封存並清除,以避免達到其大小上限。

適用於

另請參閱