FeaturedIT topics

How to use NLog in ASP.Net Core

NLog is a free, open-source, and easy-to-use logging framework that supports .Net Core and ASP.Net Core as well as the .Net Framework, Xamarin, and other Microsoft platforms. NLog is easy to configure and extend and comes with excellent support for log routing and management capabilities. This makes it a good choice when you must choose a logging framework that is fast and flexible.

In one of my earlier posts here, I covered the basics of NLog and how it can be used to log data to a file using .Net. In this article we will explore how we can take advantage of ASP.Net Core’s built-in support for dependency injection to use NLog as middleware.

Create an ASP.Net Core Web API project

If you’re running Visual Studio 2017, you can follow the steps outlined below to create an ASP.Net Core Web API project.

  1. Launch the Visual Studio IDE. 
  2. Click on File > New > Project.
  3. Select “ASP.Net Core Web Application (.Net Core)” from the list of templates displayed.
  4. Specify a name for the project.
  5. Click OK to save the project.
  6. Select “API” in the “New .Net Core Web Application…” window.
  7. Select the version of ASP.Net Core you want to use.
  8. Uncheck the “Enable Docker Support” box and select “No Authentication” as we won’t be using either of these here.
  9. Click OK.

This will create a new ASP.Net Core Project in Visual Studio 2017. Next, install the following two packages to the project via the NuGet Package Manager in Visual Studio: 

Related Articles

Back to top button