Skip to main content

Application Logging

This section provides information on how to log information in your worker applications.

Logging in worker commands

In your worker application, the default logging infrastructure is already set up. Use the Logger property of the command to quickly log messages using the ILogger API.

using Taskurai.Models;
using Taskurai.Worker;

public class TestCommand : TaskuraiCommand
{
public override async Task ExecuteAsync(TaskuraiTaskContext context, CancellationToken cancellationToken)
{
// Execute the command...

Logger.LogInformation("TestCommand - RequestedVersion: {RequestedVersion}", RequestedVersion.ToString());

var completeInput = new CompleteTaskInput()
{
Status = TaskStatusType.Succeeded,
StatusCode = 200
};

await context.CompleteTaskAsync(completeInput);
}
}

Structured logging

It is possible to use structured logging and create custom columns in the logs:

Logger.LogInformation("TestCommandV2 - RequestedVersion: {RequestedVersion}", RequestedVersion.ToString());

The custom column will be returned like this example:

  {
"taskRunCount": 1,
"taskId": "340695d7-8414-41e5-93c3-8e3b36182ba4",
"command": "testCommand@2",
"taskCorrelationId": "340695d7-8414-41e5-93c3-8e3b36182ba4",
"sourceContext": "Taskurai.Worker.TaskuraiWorkerParallel",
"workerName": "TestWorker",
"containerImage": "taskuraisample.azurecr.io/taskurai-worker-sample:latest",
"plainMessage": "",
"timeGenerated": "2024-04-29T20:22:30.7906401+00:00",
"message": "TestCommandV2 - RequestedVersion: \"2\"",
"time": "2024-04-29T20:22:06.1813908+00:00",
"timestamp": 1714422126.18139,
"workerRevision": "testworker--dxysjnpuexihm",
"customColumns": {
"requestedVersion": "2"
},
"logTableName": "TaskuraiConsoleLogs"
}

Limitations:

  • The recommended maximum number of dynamic columns is 50.
  • Column names have a maximum of 45 characters.
  • Avoid deep JSON nesting levels for performance.

Overcoming limitations:

Taskurai uses structured logging for the default columns. While you can add custom columns, it is recommended take the limitations in consideration. Parsing custom columns can have performance penalties.

When values do not need to be added as custom columns, define them as an interpolated value:

Logger.LogInformation($"TestCommandV2 - RequestedVersion: {RequestedVersion.ToString()}");

Logging configuration

The Worker SDK uses the Serilog library to offer structured logging.

Logging can be configured in the appsettings.json for each worker that is deployed to Taskurai.

appsettings.json
{
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Warning",
"System": "Warning",
"Taskurai": "Information",
"Taskurai.Worker": "Information"
}
}
},
...
}