SkillAgentSearch skills...

Apache.log4net.Extensions.Logging

log4net logger provider implementation for Microsoft.Extensions.Logging.

Install / Use

/learn @joshclark/Apache.log4net.Extensions.Logging
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

apache.log4net.Extensions.Logging Build status NuGet Version

A log4net provider for Microsoft.Extensions.Logging, the logging subsystem used by ASP.NET Core.

This package routes ASP.NET log messages through log4net, so you can get information about ASP.NET's internal operations logged to the same log4net appenders as your application events.

Instructions

First, install the apache.log4net.Extensions.Logging NuGet package into your web or console app.

Install-Package apache.log4net.Extensions.Logging 

(Note: You should use version 1.x for .NET Core 1.x projects and version 2.x for .NET Core 2.x projects because of breaking change in .NET Core logging API introduced in .NET Core 2.0)

Next, create a log4net.config in the root of your project, see log4net.config for examples. You can also use the config included with the sample app

Finally (.NET Core 1.x), in your Startup class's Configure() method, remove the existing logger configuration entries and call AddLog4Net() on the provided loggerFactory.

  public void Configure(IApplicationBuilder app,
                        IHostingEnvironment env,
                        ILoggerFactory loggerfactory,
                        IApplicationLifetime appLifetime)
  {
      loggerfactory.AddLog4Net();
      

Finally (.NET Core 2.x), in your Startup class's ConfigureServices() method, remove the existing logger configuration entries and call AddLog4Net() on the ILoggerBuilder in AddLogging.

  public IServiceProvider ConfigureServices(IServiceCollection services)
  {
      services.AddLogging(builder => builder.AddLog4Net());
      

Related Skills

View on GitHub
GitHub Stars6
CategoryDevelopment
Updated5y ago
Forks5

Languages

C#

Security Score

70/100

Audited on Mar 19, 2021

No findings