Search code examples
c#visual-studio-2017.net-corelog4net

Log4Net with .net core 2 and framework Wrapper


I'm prototyping a .net core 2 web application. I've been asked to use Log4Net for handling our logging, but I want to put it in a .net framework 4.6.1 wrapper project as to allow for changing out the internal logging systems without having to update all of the method calls throughout the site.

Everything that I've found so far is for doing one or the other. Wrapping the log4net in 4.6.1 or doing a direct reference to the .net core.

So far, my 2 main exceptions are "FileNotFoundException" for when I use it as a direct reference, or when I do the PackageReference in the Framework proejct files I get a "Logging is not compatible with netcoreapp2.0. Logging is framework 4.6.1.


Solution

  • First, I would recommend making your wrapper using .NET standard 1.3 as this is the currently .NET core version supported by log4net, plus, this would allow you to reference this wrapper in .NET core and .NET framework 4.6 and up.

    Second, see: https://stackify.com/making-log4net-net-core-work/ for some more info on getting log4net working with .NET core.