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 可指定在事件日志已满时放弃新条目。 如果使用此设置,请确保定期存档和清除事件日志,以避免达到其最大大小限制。

适用于

另请参阅