Search code examples
c#asp.netlogginglog4netevent-log

can I limit log4net to eventview by size?


My webApplication uses log4net that writes to event-viewr.

I want to limit its size to 1 GB.

is there any way to do this within the webcofig? (as it can be limited to log file)


Solution

  • Yes, but not by default. Existing EventLogAppender does not support MaximumLogSize.

    Event Log API does support size constraints (EventLog.MaximumKilobytes and EventLog.OverflowAction ) so you can extend existing appender and provide this feature.

    From the MSDN

    The MaximumKilobytes property represents the size limit of the event log file. When the event log reaches the size limit, the configured OverflowAction value determines whether new entries are discarded, or whether new entries overwrite older entries.

    --

    The OverflowAction value that specifies the configured behavior for storing new entries when the event log reaches its maximum log size. The default is OverwriteOlder.