Job logs

The engine uses Serilog Serilog.AspNetCore package for logging through standard .NET logging.

Make sure to configure .NET to use Serilog like this:

builder.Host.UseSerilog((context, services, configuration) =>
{
    configuration.ReadFrom.Configuration(context.Configuration);
});

And your appSettings.json should include:

"Serilog": {
  "Using": ["CommerceMind.Nexus.Jobs"],
  "WriteTo": [{ "Name": "NexusJobLogs" }]
}

More info here: https://blog.datalust.co/using-serilog-in-net-6/

Included in Nexus is a special Serilog log sink that captures all logs that occur during the execution of a job. Both logs from inside the IScheduledJob.ExecuteAsync() method and any logs happening inside other classes called by the job are captured as part of that job run.

IJobLogWriter

Collected job logs are continuously flushed to the IJobLogWriter by the job executor as they occur.

There's two 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.AddNexusScheduledJobs(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 forever, but you can configure it like this:

builder.Services.AddNexusScheduledJobs(options =>
{
    options.HistoricalRunsRetention = TimeSpan.FromDays(10);
});

IJobLogProvider

When requesting job logs for a specific run the IJobLogProvider service is called. The built in implementations that stores logs in the database also implement this interface. When calling AddNexusScheduledJobs() like the example above both the writer and the provider 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

Not using Serilog?

If you for some reason don't want to use Serilog you can still make job logs in work in the Nexus Admin UI. Nexus uses standard .NET logging and sets scopes to track the context for when a job or a function is running. Which means that as long as the log provider you're using saves the scope properties Nexus.CorrelationId and Nexus.JobName in a way that makes it filterable later on you'll be able to implement your own IJobLogProvider and make logs visible in the Admin UI without using Serilog.