英語で読む

次の方法で共有


OverflowAction 列挙型

定義

最大ファイル サイズに達したイベント ログ内のエントリの処理方法を指定します。

C#
public enum OverflowAction
継承
OverflowAction

フィールド

名前 説明
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設定します。 プロパティを使用して、 の EventLog 現在構成されている動作を OverflowAction 確認します。

適用対象

製品 バージョン
.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