Default logging with ILogger occurs in console window but in production evironments, one may want to log in some file to refer to it later, here Serilog comes into play, to write logs to some file.
We can inject ILogger into controller constructors as ILogger functionality comes with ASP.NET core
public class AboutModel : PageModel { private readonly ILogger _logger; public AboutModel(ILogger<AboutModel> logger) { _logger = logger; } public void OnGet() { _logger.LogInformation("About page visited at {DT}", DateTime.UtcNow.ToLongTimeString()); } }
Comments
Post a Comment