Categories
General

Log4net Support for .Net Core

Logs are very helpful when it comes to troubleshooting problems. One of the most popular logging libraries is Apache’s log4net. With the recent release of .Net core, libraries need to make changes to accommodate it. In this post, I want to inspect the commit that takes log4net closer to support .net core.

The source code is hosted by Apache at http://svn.apache.org/viewvc/logging/log4net/trunk and it uses Subversion. They also have a git mirror at https://github.com/apache/log4net.

Now that you know where the code is, let’s inspect the major changes for this revision.

After getting the source code from the subversion repo, take a look at revision 1756257 that happened on Saturday August 13 2016 at 7:47am by chlowell. There is a brand new folder dedicated to .Net core called netstandard which is found in /logging/log4net/trunk/netstandard. Here you will find global.json, log4net.xproj, project.json, and others files.

Now let’s take a look at existing files that were modified to support .Net core. ConsoleAppender.cs line 123 has the following change:


#if NETSTANDARD1_3
if (CultureInfo.InvariantCulture.CompareInfo.Compare(ConsoleError, v, CompareOptions.IgnoreCase) == 0)
#else
if (string.Compare(ConsoleError, v, true, CultureInfo.InvariantCulture) == 0)
#endif

Here the code is checking for a very specific .Net core version 1.3 and if the end user has that version available, the library will be compiled with that block of code.
If you continue with the other modified files, you will see similar code.

As you can see, there was a lot of code changes needed to get the initial support for .Net core. However, this open source library needs help to move forward. We need help testing these changes, updating documentation, etc.

I’m in the process of sending a pull request to have a beta version to nuget soon. Having a beta version in nuget will make it easier to test it and provide feedback.

Leave a Reply

Your email address will not be published. Required fields are marked *