Reputation: 311
I have a web project which still working properly until I ve updated some packages then I faced a run time error with this line of code
//Log4Net configuration
AbpBootstrapper.IocManager.IocContainer
.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net()
.WithConfig(Server.MapPath("log4net.config"))
);
the error message said that "Could not find file" even though the file is exist.
Any answers will be appreciated. Thanks in advance.
Upvotes: 1
Views: 1780
Reputation: 9624
For AspNet Core, you can use HostingEnvironment.ContentRootPath
//Log4Net configuration
AbpBootstrapper
.IocManager
.IocContainer
.AddFacility<LoggingFacility>(f => f.UseAbpLog4Net()
.WithConfig(Path.Combine(_hostingEnvironment.ContentRootPath, "log4net.config")));
PS: You need to inject IHostingEnvironment
private readonly IHostingEnvironment _hostingEnvironment;
public Startup(IHostingEnvironment env)
{
_hostingEnvironment = env;
}
Update-1 : for AspNet MVC
Take a look at the HttpRuntime.AppDomainAppPath
Update-2 : for AspNet MVC - Use tilda for MapPath
Server.MapPath("~\log4net.config")
Upvotes: 2