TaskHub.Shared uses Serilog as its primary logging engine, pre-configured with industry-standard sinks and automatic enrichment.
ServiceName and ServiceVersion.Environment.TraceId and SpanId for correlation with traces.The simplest way to enable logging is via the FullHostBuilder. Alternatively, use the extension method:
using TaskHub.Observability.Logger;
builder.Host.AddAppSerilog();
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"
}
}
]
}
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);
}
}
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.