Plugging in an existing third-party logger provider
NLog
was one of the very first loggers that was available as a .NET Standard library and usable in ASP.NET Core. NLog
also already provides a logger provider to easily plug into ASP.NET Core.
You will find NLog
via NuGet (https://www.nuget.org/packages/NLog.Web.AspNetCore) and on GitHub (https://github.com/NLog/NLog.Web). Even if NLog
is not yet explicitly available for ASP.NET Core 5.0, it will nevertheless work with this version:
- We need to add an
NLog.Config
file that defines two different sinks to log all messages in a single log file, and custom messages only in another file. Since this file is too long to print, you can view it or download it directly from GitHub: https://github.com/PacktPublishing/Customizing-ASP.NET-Core-5.0/blob/main/Chapter01/LoggingSample5.0/NLog.Config. - We then need to add the
NLog
ASP.NET Core package from NuGet:dotnet add package NLog.Web.AspNetCore
Important note
Be sure that you are in...