Skip to content
AgileLogics
3 min read

Debugging & Logging

Prerequisites: Unit testing with xUnit

A real application logs through ILogger (from Microsoft.Extensions.Logging) instead of Console.WriteLine — supporting log levels and structured, filterable output, the same idea as Java's SLF4J/Logback.

public class OrderService {
    private readonly ILogger<OrderService> _logger;

    public OrderService(ILogger<OrderService> logger) {
        _logger = logger;
    }

    public void PlaceOrder(string id) {
        _logger.LogInformation("Placing order {OrderId}", id);
    }
}

ILogger is typically obtained through dependency injection (covered fully in Level 3) rather than constructed directly.