Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies

Wednesday, August 24, 2022

ASP.NET Core Web API – Logging With NLog

 

Why is logging so important during the application development? Well, while your application is in the developing stage it is very easy to debug the code and to find out what went wrong. But, can you debug in the production environment?

Of course not. 

That is why logging messages are a great way to find out what went wrong and where did errors happen in your code in the production environment. .NET Core has its own implementation of logging messages, but in all my projects, I prefer to create my own custom logger service. 

So, let’s start.

Creating Required Projects

Let’s create two new projects. Name the first one Contracts. We are going to store interfaces inside this project. Name the second one LoggerService. We are going to use it for the logger logic.

To create a new project:

  • Right-click on the solution window,
  • Choose Add and then NewProject. We are going to choose the Class Library and name it Contracts:

Do the same thing for the second project, just name it LoggerService.

With these two new projects in place, we need to reference the LoggerService project to the main project.

No comments:

Post a Comment