This document will help you learn about logging in NBomber tests, options to configure, and also it gives you an introduction to Serilog logger and data sinks.
Logging in NBomber tests
NBomber is using Serilog library for logging. You don't need to install it, it's included already.
If you want to use logger out of NBomber context you can get access via static property.
By default NBomber logger writes logs only to console and file sinks with the following configuration.
What is sink?
Structured log events (messages) are written to sinks and each sink is responsible for writing it to its own backend, database, store etc.
- Console sink is a mandatory sink which NBomber use to print out text on console. This sink can't be customized or overridden. Console sink prints only Info and Warning logs.
- File sink is a mandatory sink which NBomber use to write logs into file. This sink can't be customized or overridden. Also, File sink writes all types of logs (Verbose, Debug, Info, Warning, Error, Fatal), therefore if you decide to trace some request/response payload this sink is way to go.
You can enrich or customize default logger configuration using some other sinks.
Make sure that you always return a new instance (not from a variable) of LoggerConfiguration. This limitation is mandatory since Serilog logger does not allow to create multiple instances from the same instance of LoggerConfiguration.
Another way that is more appropriate for production use cases is configuring logger via infrastructure config file.
You can also use NBomber CLI to dynamically specify file path to the infrastructure config.
Here is an example of infrastructure config file.
Serilog supports many data storages to save your logs. You can check this list. But the most used is Elasticsearch. Let's try to integrate our NBomber with Elasticsearch to ship our logs there and be able to analyze them using full-text search or aggregation queries.
You should have installed Elasticsearch database. If you don't have you can use Docker setup.
Add Elasticsearch sink
Configure Elasticsearch sink
For more information about Elasticsearch sink configuration, please use this link.