TaskHub.Shared

Logging with Serilog

TaskHub.Shared uses Serilog as its primary logging engine, pre-configured with industry-standard sinks and automatic enrichment.

Features

Registration

The simplest way to enable logging is via the FullHostBuilder. Alternatively, use the extension method:

using TaskHub.Observability.Logger;

builder.Host.AddAppSerilog();

Configuration

Logging is configured through the Serilog section in appsettings.json.

"Serilog": {
  "MinimumLevel": {
    "Default": "Information",
    "Override": {
      "Microsoft": "Warning",
      "System": "Warning"
    }
  },
  "WriteTo": [
    {
      "Name": "Console",
      "Args": {
        "formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
      }
    },
    {
      "Name": "Loki",
      "Args": {
        "serverUrl": "http://loki:3100"
      }
    }
  ]
}

Usage

Inject ILogger<T> as usual. The structured properties will be handled by the configured sinks.

public class MyService(ILogger<MyService> logger)
{
    public void DoWork(Guid id)
    {
        // Use message templates for structured data
        logger.LogInformation("Processing item with ID {ItemId}", id);
    }
}

Troubleshooting

If you don’t see logs in your sink (e.g., Loki), check the MinimumLevel configuration and ensure the serverUrl is reachable from the service container.