Dhana
Dhana

Reputation: 1658

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 enter image description here

Upvotes: 0

Views: 3823

Answers (3)

Tom Sun
Tom Sun

Reputation: 24569

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.

Upvotes: 1

Jeff
Jeff

Reputation: 36603

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

Upvotes: 0

Thiago Custodio
Thiago Custodio

Reputation: 18362

Rather than use the local storage which the intent is to provide temporary file storage for IIS and web application frameworks, I would recommend you to write your logs on Azure Storage.

Upvotes: 0

Related Questions