burak ramazan
burak ramazan

Reputation: 156

Asp.net Core Log4net FileNotFoundException

I need to use log4net on a new Asp.net Core app. I get FileNotFoundException error when I run the project.

Startup.cs

ConfigureServices method:

services.AddLogging(builder =>
{
    builder.AddConfiguration(Configuration.GetSection("Logging"))
           .AddConsole()
           .AddDebug();
 });

Configure Method:

   loggerFactory.AddLog4Net("log4net.config");  

I get the error on this line. Log4net.config file is in the UI project.

Why am I getting this error?

Upvotes: 0

Views: 735

Answers (2)

burak ramazan
burak ramazan

Reputation: 156

Thanks for your help. I've solved this problem. I changed the copy to output directory property for log4net.config file to copy always.

Upvotes: 1

kemal akoğlu
kemal akoğlu

Reputation: 182

Could you change your configure method with this;

log4netConfig.Load(File.OpenRead("log4net.config"));

Upvotes: 0

Related Questions