简体   繁体   中英

How to refer wwwroot path files in web.config - Azure App service

I deployed .Net web api in Azure App service. My Log folder located in WWWROOT Folder. My Folder structure like below

↓WWWROOT
 >bin
 ↓Logs
  >TraceLog.log 
Web.Config

I want to refer

TraceLog.log

path in web.config.

I tried following ways

fileName="%home%\site\wwwroot\Logs\TraceLog.log" 
fileName="C:\DWASFiles\Sites\[your websitnmame]\site\wwwroot\Logs\TraceLog.log"
fileName="C:\DWASFiles\Sites\[your-websitename]\VirtualDirectory0\Logs\TraceLog.log"
fileName="~\Logs\TraceLog.log"
fileName="\Logs\TraceLog.log"

but getting this error 在此处输入图片说明

我建议您不要在Azure存储上编写日志,而应该使用旨在为IIS和Web应用程序框架提供临时文件存储的本地存储。

You can't. They designed it so it's not readinly available. Neither the AppDomain.BaseDirectory or the Environment.CurrentDirectory points there...but you can find it under the %HOME% environment variable...but you must call ExpandEnvironmentVariables in code to refer to the path or specify the full path

You should note that your web.config is basically ignored since the app service runtime has its own web.config...so any references to paths must be in your code, not your web.config

As Thiago Custodio and Jeff mentioned that we could use code easily do that. In your case, please have a try to use the following code.

string traceLogPath = Environment.GetEnvironmentVariable("HOME") + @"\site\wwwroot\logs\TraceLog.log";

As Azure WebApp is sanbox , d:\\home is available for the sandbox with read/write access.File structure on azure please refer to this document .

Home directory access (d:\\home)

Every Azure Web App has a home directory stored/backed by Azure Storage. This network share is where applications store their content. This directory is available for the sandbox with read/write access.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM