Made a simple net standard 2.0 project.
Here's the code
private Logger _errorLog = LogManager.GetLogger("ErrorsLogger");
private Logger _tradesLog = LogManager.GetLogger("TradesLogger");
_errorLog.Error(message);
and here's the config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="ErrorsLogger" xsi:type="File" fileName="ErrorsLog.txt" />
<target name="TradesLogger" xsi:type="File" fileName="TradesLog.txt" />
</targets>
<rules>
<logger name="ErrorsLogger" minlevel="Info" writeTo="ErrorsLogger" />
<logger name="TradesLogger" minlevel="Info" writeTo="TradesLogger" />
</rules>
</nlog>
</configuration>
Result:
Message: Test method UnitTestProject.UnitTest1.TestMethod1 threw exception:
System.TypeInitializationException: The type initializer for 'NLog.LogManager' threw an exception. ---> System.TypeInitializationException: The type initializer for 'NLog.LogFactory' threw an exception. ---> System.MissingMethodException: Method not found: 'System.AppDomainSetup System.AppDomain.get_SetupInformation()'.
The error is thrown on GetLogger
Same code works on .NET Framework 4.6.1 console project
Please use the template, check the inner log and list all the nlog (nuget) versions, thanks!
@Porkechebure Only NLog 4.5 supports NetStandard 2.0:
https://www.nuget.org/packages/NLog/4.5.0-rc04
Right now you are using NLog 4.4 from a NetStandard2.0 library, and it will attempt to load the unsupported NLog-dll (but fails with Method not found: System.AppDomainSetup)
Here all the info you need:
Still not resolved. Enabling internal logging ( brings up nothing into the log file (Visual studio started as administrator)
@snakefoot
Tried, check the stackoverflow post up here. Now no exception is thown but NLog doesn't produce any output file. Internal logging doesn't produce anything useful either.
What to do now?
HERE i've put up a test solution that I made to show you. Now that I've updated to Nlog 4.5 you will see that the .NET framework solution throws an error trying to get an old version of Nlog (that I've never referenced) and that .NET Core unit test solution works but doesn't produce any file.
@Porkechebure Your zipped solution is password protected, so now it is just me guessing, but it looks like you are using app.config to hold nlog.config.
Pretty sure app.config are not being used by NetCoreApps. Try to put your Nlog-config in a separate file called nlog.config and make sure it is Copy Always (In Visual Studio File Properties).
@snakefoot Very stupid by me. Sorry password is logging123
@Porkechebure No problem. Looks like your issue was resolved (when looking at stackoverflow).
@snakefoot Hello. Sorry for the delay. Yes, it was about the config file names. It's very sad this is poorly and unclearly documented around the web. Many thanks again for the help 馃憤
Most helpful comment
@Porkechebure No problem. Looks like your issue was resolved (when looking at stackoverflow).