Web applications


For web applications, the ILogger is created, shared and flushed automatically for each http request (connection).

public class HomeController : Controller
    private readonly ILogger _logger;
    public HomeController()
        _logger = Logger.Factory.Get();

    public IActionResult Index()
        _logger.Debug("Debug message");

        _logger.Info("Info message");

        return View();

Create ILogger instance

ILogger logger = Logger.Factory.Get();

Log listeners events

The registered log listeners are notified automatically as following:

GET /Home/Index                         <---- OnBeginRequest()

ILogger logger = Logger.Factory.Get();

logger.Debug("Debug message");          <---- OnMessage()

logger.Debug("Info message");           <---- OnMessage()

HTTP 200 OK                             <---- OnFlush()