File log
Location: file module.
Features
Customizable output templates.
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
FileLog
instances inside a single process may write to the same file without performance penalties.Log
method is nonblocking: log events are placed into an internal queue, buffered and efficiently written to files in the background.
Configuration
FileLog
instances 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 FileLogSettings
. FileLog
will 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 EventsQueueCapacity
option: it has a per-file scope and can't be changed dynamically.
Usage tips
Keep in mind that log messages are written to files in the background. Use
Flush
orFlushAsync
methods ofFileLog
to ensure that all logged events have been actually written at any given moment.Remember to dispose of
FileLog
instances when they are no longer needed in order to close file handles.Dispose
method 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
EventsLost
property of a singleFileLog
instance or staticTotalEventsLost
property to check if any events have been discarded.If any log events are lost due to internal queue overflow,
FileLog
emits a special diagnostic message that looks like this:When encountering any other severe internal error (such as inability to open the file),
FileLog
reports it to console.FileLog
can be configured from any external source (such as a local settings file) with Vostok.Configuration: just construct the log with a delegate that obtainsFileLogSettings
from aConfigurationProvider
.
Last updated