Číst v angličtině Upravit

Sdílet prostřednictvím


OverflowAction Enum

Definition

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Specifies how to handle entries in an event log that has reached its maximum file size.

public enum OverflowAction
Inheritance
OverflowAction

Fields

Name Value Description
DoNotOverwrite -1

Indicates that existing entries are retained when the event log is full and new entries are discarded.

OverwriteAsNeeded 0

Indicates that each new entry overwrites the oldest entry when the event log is full.

OverwriteOlder 1

This field is deprecated.

Examples

The following example enumerates the event logs defined on the local computer and displays configuration details for each event log.

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;
        }
    }
}

Remarks

Every event log has a maximum size limit and a configurable setting that provides the rule for writing new entries at that limit. When the event log has reached its maximum size, you can specify one of the following rules:

  • New entries will be discarded.

  • New entries will overwrite older entries.

Use the ModifyOverflowPolicy method to set the overflow behavior for an EventLog. Check the current configured behavior of an EventLog through its OverflowAction property.

Upozornění

The OverwriteOlder behavior is deprecated. Using this value might cause the Event Log to behave as if the DoNotOverwrite value was used instead, which will cause events to be discarded when the log is full.

Applies to

Produkt Verze
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.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
.NET Standard 2.0 (package-provided)
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10