Skip to main content

Logging

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

Popular posts from this blog

Migrations

Migrations help us ensure that the database schema and the domain model in the appliation are in sync. In real world projects, data models change as features get implemented: new entities or properties are added and removed, and database schemas need to be changed accordingly to be kept in sync with the application. Migrations provides a way to incrementally update the database schema to keep it in sync with the application's data model while preserving existing data in the database. More on Migrations with EF (Entity Framework) here Dapper and Migrations: Dapper is a lightweight Object-Relational Mapping (ORM) library for .NET that provides a simple way to interact with databases. Unlike full-fledged ORMs like Entity Framework, Dapper does not have built-in support for database migrations. Instead, it focuses on efficiently executing SQL queries and mapping the results to .NET objects.

Introduction

  This blog is a collection of key points and noteworthy information regarding buidling a webAPI with ASP.NET Core Program.cs Controller example ActionResult and Other Controller Actions Return Types in ASP.NET Core web API Attributes  Http Patch Logging Migrations ORMs