Adding a log4Net provider in .net core console app

I recently was developing a console application in .net core, where I had to use log4net logging.

In the standard asp.net core approach we can use:

But that is asp.net core and I don’t want to reference that in my console app.

In order to solve it, I had to implement my own Log4NetProvider, that would implement ILoggerProvider.

And the implementation of an actual logger:

One last touch is adding an extension for ILoggerFactory to be able to use AddLog4Net.

Now it will all works!

 

Leave a Reply

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