October 2018
Beginner to intermediate
478 pages
10h 8m
English
The logging infrastructure is already registered in the built-in dependency injection container, so all you need to do to get access to the logger is to add it as a parameter in your controller constructor so that it will be injected when the controller is created. For example, this is how the logger is injected into the GiveNTake ProductsController:
using Microsoft.Extensions.Logging;[Authorize][Route("api/[controller]")]public class ProductsController : Controller{ ... private readonly ILogger<ProductsController> _logger; public ProductsController(GiveNTakeContext context, ILogger<ProductsController> logger) { _logger = logger; ... } ...}
Whenever you need to write a log event, you need to use ...
Read now
Unlock full access