Job logs
Nexus has a ILoggerProvider
which will collect logs by job run and store in the database.
Nexus is compatible with any logging framework such as Serilog or NLog as long as it supports external providers. With Serilog writing to providers is disabled by default so you need to enable it to get Nexus logs to work:
builder.Host.UseSerilog((context, services, configuration) =>
{
configuration.ReadFrom.Configuration(context.Configuration);
// This one is important
}, writeToProviders: true);
IJobLogWriter
Collected job logs are continuously flushed to the IJobLogWriter
by the job executor as they occur.
There's three implementations of this interface built in. One for Postgres, one for SQL Server and one for SQLite and whichever database you've chosen to store job meta data is also used for logs. Logging to the database is enabled by default, but you can turn it off like this:
builder.Services.AddNexus().AddScheduledJobs(options =>
{
options.SaveLogsToDatabase = false;
});
Job logs are then stored in the database for as long as you'e set the retention for historical runs. When a historical run is deleted the logs for that run is also deleted.
The default is to store historical runs and logs for 30 days, but you can configure it like this:
builder.Services.AddNexus().AddScheduledJobs(options =>
{
options.DefaultHistoricalRunsRetention = TimeSpan.FromDays(10);
});
You can also specify this per job with the [ScheduledJob]
attribute like this:
[ScheduledJob("MyJob", HistoricalRunsRetention = "30.00:00")]
public class MyJob : IScheduledJob
{
...
}
The string you set is any string that can be passed to TimeSpan.Parse()
or the special string forever
to indicate that Nexus should never delete the job history.
IJobLogReader
When requesting job logs for a specific run the IJobLogReader
service is called. The built in implementations that stores logs in the database also implement this interface. When calling AddNexus().AddScheduledJobs()
like the example above both the writer and the reader gets registered.
If you send your logs to an external source like Elastic Search or Application Insights you can provide your own implementation of this interface.
Note
You can view the job logs in the admin UI where all logs for a single job run are displayed to make troubleshooting a job easier