Plugging in an existing third-party logger provider
NLog
was one of the very first available as a .NET Standard library, and it can be used 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 6.0, it will still work with version 6.0:
- We need to add an
NLog.Config
file that defines two different sinks to log all standard 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-6.0-Second-Edition/blob/main/Chapter01/LoggingSample6.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...