var fileLog = new FileLog(new FileLogSettings());
var dynamicallyConfiguredLog = new FileLog(() => ObtainSettings());
- Customizable rolling strategies:
- By size (roll over to a new file when current one reaches given size)
- By time (roll over to a new file every second/minute/hour/day)
- Hybrid (both by size and time)
- Automatic cleanup of stale files
- Multiplexing: multiple
FileLoginstances inside a single process may write to the same file without performance penalties.
Logmethod is nonblocking: log events are placed into an internal queue, buffered and efficiently written to files in the background.
FileLoginstances are configured with
FileLogSettings, exposing following options:
All of these parameters are optional.
Most of listed options support dynamic reconfiguration when a constructor with
Func<FileLogSettings>is used and provided delegate returns different instances of
FileLogwill react to these changes by either reopening the file, switching to a new file or simply using the new values where applicable.
The only notable exception to this rule is the
EventsQueueCapacityoption: it has a per-file scope and can't be changed dynamically.
- Keep in mind that log messages are written to files in the background. Use
FileLogto ensure that all logged events have been actually written at any given moment.
- Remember to dispose of
FileLoginstances when they are no longer needed in order to close file handles.
Disposemethod also flushes all remaining messages before closing the file.
- Internal queue with limited capacity implies that log messages may be lost in the event of overflow (see guarantees section for more on this topic). Use
EventsLostproperty of a single
FileLoginstance or static
TotalEventsLostproperty to check if any events have been discarded.
- If any log events are lost due to internal queue overflow,
FileLogemits a special diagnostic message that looks like this:
- [FileLog] Buffer overflow. 100 log events were lost (events queue capacity = 50000).
- When encountering any other severe internal error (such as inability to open the file),
FileLogreports it to console.
FileLogcan be configured from any external source (such as a local settings file) with Vostok.Configuration: just construct the log with a delegate that obtains