Using advanced NLog features in ASP.NET Core

Take advantage of the free and flexible NLog to log your application data with the features and efficiency you need

Using advanced NLog features in ASP.NET Core

NLog is an open source and lightweight logging platform with rich log routing and management capabilities. NLog is also easy to configure and extend. I’ve discussed using NLog in .NET and using NLog in ASP.NET Core in earlier posts. In this article, I will discuss how we can perform more advanced operations using NLog.

Specifically, we will look at how to configure NLog using a .config file as well as code-based configuration, how to automatically rotate logs, how to use a database as a log target, and how to improve performance by logging data asynchronously. I will also share some best practices for using NLog. 

Create an ASP.NET Core MVC project in Visual Studio

First off, let’s create an ASP.NET Core project in Visual Studio 2019. Assuming Visual Studio 2019 is installed in your system, follow the steps outlined below to create a new ASP.NET Core MVC project in Visual Studio.

  1. Launch the Visual Studio IDE.
  2. Click on “Create new project.”
  3. In the “Create new project” window, select “ASP.NET Core Web Application” from the list of templates displayed.
  4. Click Next.
  5. In the “Configure your new project” window, specify the name and location for the new project.
  6. Optionally, select the “Place solution and project in the same directory” check box.
  7. Click Create.
  8. In the “Create a New ASP.NET Core Web Application” window shown next, select .NET Core as the runtime and ASP.NET Core 2.2 (or later) from the drop-down list at the top.
  9. Select “Web Application (Model-View-Controller)” as the project template to create a new ASP.NET Core MVC application. 
  10. Ensure that the check boxes “Enable Docker Support” and “Configure for HTTPS” are unchecked as we won’t be using those features here.
  11. Ensure that Authentication is set to “No Authentication” as we won’t be using authentication either.
  12. Click Create. 

To continue reading this article register now

How to choose a low-code development platform