-
Notifications
You must be signed in to change notification settings - Fork 197
Durability
When you are sending log events to Serilog, they are buffered by default on the sink. When there are more than 50 items or the time period of 2 seconds is passed, the events are flushed to the sink itself. You can of course change those values. However, if Elasticsearch is not available, the sink will fail and report this to the Selflog of Serilog. Given that this is not easily discoverable, you might end up with missing events.
The durability option allows you to store the events first in a disk buffer and gradually send them the Elasticsearch in the background as long as the server is available. The sink will keep track what has been sent or not and will continue when possible.
It is pretty easy to enable buffering locally. Just pass in the storage location like shown below.
var loggerConfig = new LoggerConfiguration()
.WriteTo.Elasticsearch(new ElasticsearchSinkOptions(new Uri("http://localhost:9200") ){
BufferBaseFilename = "./logs/buffer"
});
var logger = loggerConfig.CreateLogger();
Whenever you now write events to the Serilog system, they will end up first in the /logs/ folder and are prefixed with the name buffer and have a unique date. The files will automatically be cleaned up.
Note: do make sure that the process running the application has enough permissions to access this folder and create, delete files.