简体   繁体   English

ASP零:System.IO.FileNotFoundException:找不到文件'c:\\ windows \\ system32 \\ inetsrv \\ log4net.config'

[英]ASP Zero :System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\log4net.config'

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 我有一个Web项目,在我更新了一些软件包之前,它仍然可以正常工作,然后在此行代码中遇到运行时错误

    //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. 提前致谢。

For AspNet Core, you can use HostingEnvironment.ContentRootPath 对于AspNet Core,可以使用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 PS:您需要注入IHostingEnvironment

 private readonly IHostingEnvironment _hostingEnvironment;

 public Startup(IHostingEnvironment env)
 {              
    _hostingEnvironment = env;
 }

Update-1 : for AspNet MVC Update-1:对于AspNet MVC

Take a look at the HttpRuntime.AppDomainAppPath 看看HttpRuntime.AppDomainAppPath


Update-2 : for AspNet MVC - Use tilda for MapPath Update-2:对于AspNet MVC-将tilda用于MapPath

Server.MapPath("~\log4net.config")

See https://www.roelvanlisdonk.nl/2009/05/25/asp-net-could-not-find-a-part-of-the-path-cwindowssystem32inetsrv/ 参见https://www.roelvanlisdonk.nl/2009/05/25/asp-net-could-not-find-a-part-of-the-path-cwindowssystem32inetsrv/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 File.Move错误-System.IO.FileNotFoundException:找不到文件&#39;c:\\ windows \\ system32 \\ inetsrv - File.Move Error - System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv 找不到文件 &#39;c:\\windows\\system32\\inetsrv\\xxx.xlsx&#39; - Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx' 访问路径 &#39;c:\windows\system32\inetsrv\config\&#39; 被拒绝 - Access to the path 'c:\windows\system32\inetsrv\config\' is denied 如何使用c#asp.net获取C:\\ Windows \\ System32 \\ inetsrv \\ config文件夹的访问控制 - How to get access control of C:\Windows\System32\inetsrv\config folder using c# asp.net System.IO.FileNotFoundException:找不到文件 - System.IO.FileNotFoundException : Could not find file .NET 7 System.IO.FileNotFoundException:找不到文件 - .NET 7 System.IO.FileNotFoundException: Could not find file System.IO.FileNotFoundException: 在 asp.net MVC 中“找不到文件” - System.IO.FileNotFoundException: 'Could not find file ' in asp.net MVC Xamarin Android System.IO.FileNotFoundException:找不到文件异常 - Xamarin Android System.IO.FileNotFoundException: Could not find file Exception System.IO.FileNotFoundException: &#39;找不到文件 Xamarin Forms - System.IO.FileNotFoundException: 'Could not find file Xamarin Forms 控制台应用程序:System.IO.FileNotFoundException:找不到文件 - Console Application: System.IO.FileNotFoundException: Could not find file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM