Search code examples
c#log4net.net-standardlog4net-configurationlog4net-appender

How do I setup a FileAppender logger from log4net for a .NET Standard 2.0 class library?


How do I setup a File Appender logger from log4net for a class library using .NET Standard 2.0? I don't have an AssemblyInfo.cs. I think I have a fundamental misunderstanding that's leading to my confusion with this, so this may be a simple answer, but I just started a class library that I want to be accessible to as many projects as possible in our solutions and have internal logging from the get-go.

Any and all suggestions/help is much appreciated.


Solution

  • There is nothing special about the AssemblyInfo.cs file. The attribute to configure log4net can be put in any file in the assembly.

    That being said I would recommend against using log4net directly and instead use a ILogger from the NuGet package Microsoft.Extensions.Logging.Abstractions. This allows the consumer of your library use any logging system they want instead of being tied to only using log4net.