JessicaOO
JessicaOO

Reputation: 98

How to inject Log4net logging in .net core 3.1 app

I am using .net core 3.1 app. I would like to configure log4net loggigng mechanism properly. I did it before with .net framework. Can someone let me know what is the best approach?

Thank you in advance.

Upvotes: 2

Views: 1881

Answers (1)

mike
mike

Reputation: 1290

I assume you have added log4net to you project with log4net.config file. In this case first you need to install package Microsoft.Extensions.Logging.Log4Net.AspNetCore. Next thing is to configure it in the middleware into the startup configure:

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
       loggerFactory.AddLog4Net();
}

If you have any additional questions feel free to ask.

Upvotes: 6

Related Questions