I'm currently creating a common library from my work that would implement an abstracted logger using NLog.
I've created a .NET Core class library targeting .NET 4.6.1 and implemented NLog, but when I try to execute a unit test that I've created, I've noticed that the nlog.config file is not being picked up. I've also followed the instruction stated https://github.com/NLog/NLog.Extensions.Logging, but I've noticed that it only targets Asp.Net Core and not for .NET Core Class Library solution.
My question is, (given that it is my first time to foray to .NET core) is the instructions stated on the link above applicable for .Net Core class libraries too, or is there a different way to implement this?
Or should I end up not using .Net Core and go for more traditional .NET Class library implementation instead?
Many thanks!
It difficult to find the config file when running as unit test. Different frameworks are using different locations. The following options should work
Manually find the config file location as pass it to NLog. Use
instead of
ConfigureNLog()
, orCreate the XML as string and feed it to NLog: instead of
ConfigureNLog
, useIt works with or without ASP.NET. The ASP.NET parts will be moved to the NLog.Web package in the future