OverflowAction 列舉

定義

代表事件記錄檔累積到最大檔案容量時,應如何處理記錄檔內的資料。

C#
public enum OverflowAction
繼承
OverflowAction

欄位

名稱 Description
DoNotOverwrite -1

當事件記錄檔容量已達上限時,保留原有項目,將新的項目丟棄。

OverwriteAsNeeded 0

當事件記錄檔容量已達上限時,用最新的項目覆寫最舊的項目。

OverwriteOlder 1

當事件記錄檔容量已達上限時,舊的項目只要存放期間超過 MinimumRetentionDays 屬性值所設定的天數,就會被新的項目覆寫。 當事件記錄檔滿載時,如果沒有任何事件的存放期間超過 MinimumRetentionDays 屬性值指定的天數,便將新的事件丟棄。

範例

下列範例會列舉本機計算機上定義的事件記錄檔,並顯示每個事件記錄檔的組態詳細數據。

C#
static void DisplayEventLogProperties()
{
    // Iterate through the current set of event log files,
    // displaying the property settings for each file.

    EventLog[] eventLogs = EventLog.GetEventLogs();
    foreach (EventLog e in eventLogs)
    {
        Int64 sizeKB = 0;

        Console.WriteLine();
        Console.WriteLine("{0}:", e.LogDisplayName);
        Console.WriteLine("  Log name = \t\t {0}", e.Log);

        Console.WriteLine("  Number of event log entries = {0}", e.Entries.Count.ToString());

        // Determine if there is an event log file for this event log.
        RegistryKey regEventLog = Registry.LocalMachine.OpenSubKey("System\\CurrentControlSet\\Services\\EventLog\\" + e.Log);
        if (regEventLog != null)
        {
            Object temp = regEventLog.GetValue("File");
            if (temp != null)
            {
                Console.WriteLine("  Log file path = \t {0}", temp.ToString());
                FileInfo file = new FileInfo(temp.ToString());

                // Get the current size of the event log file.
                if (file.Exists)
                {
                    sizeKB = file.Length / 1024;
                    if ((file.Length % 1024) != 0)
                    {
                        sizeKB++;
                    }
                    Console.WriteLine("  Current size = \t {0} kilobytes", sizeKB.ToString());
                }
            }
            else
            {
                Console.WriteLine("  Log file path = \t <not set>");
            }
        }

        // Display the maximum size and overflow settings.

        sizeKB = e.MaximumKilobytes;
        Console.WriteLine("  Maximum size = \t {0} kilobytes", sizeKB.ToString());
        Console.WriteLine("  Overflow setting = \t {0}", e.OverflowAction.ToString());

        switch (e.OverflowAction)
        {
            case OverflowAction.OverwriteOlder:
                Console.WriteLine("\t Entries are retained a minimum of {0} days.",
                    e.MinimumRetentionDays);
                break;
            case OverflowAction.DoNotOverwrite:
                Console.WriteLine("\t Older entries are not overwritten.");
                break;
            case OverflowAction.OverwriteAsNeeded:
                Console.WriteLine("\t If number of entries equals max size limit, a new event log entry overwrites the oldest entry.");
                break;
            default:
                break;
        }
    }
}

備註

每個事件記錄檔都有大小上限和可設定的設定,可提供在該限制下寫入新項目的規則。 當事件記錄檔達到其大小上限時,您可以指定下列其中一個規則:

  • 將會捨棄新專案。

  • 新專案將會覆寫較舊的專案。

  • 將會捨棄新專案,或根據現有專案的存留期覆寫現有的專案。

ModifyOverflowPolicy使用方法來設定的溢位行為EventLog。 透過其 OverflowAction 屬性檢查 的目前設定行為EventLog

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9