0
votes

I am using Azure web jobs to schedule certain tasks. The web job get deploy successfully in an Azure web app, but I am not able to relatively determine the path to the app_data folder where to log files should be stored. (web job is located in d:\home\site\wwwroot\App_Data\jobs\triggered\webjobname)

The following (absolute) path works:

<file value="d:\\home\\site\\wwwroot\\App_Data\\Logs\\WebJobLog.txt" />

The following paths do not work:

<file value="../../App_Data/Logs/WebJobLog.txt" />
<file value="/App_Data/Logs/WebJobLog.txt" />
<file value="~/App_Data/Logs/WebJobLog.txt" />

Anyone knows how to set the file path relatively?

2
why bother, its not like this path is going to change4c74356b41

2 Answers

1
votes

In general, you could specify your path as follows to achieve your purpose:

<file value="App_Data\\Logs\\WebJobLog.log" />

While for WebJobs, your webjob would be copied to a temp directory (e.g. %TEMP%\jobs\{job type}\{job name}\{random name}) by default for running, at this point your log file would under the temp folder. For more details, you could refer to WebJob Working Directory.

Based on your requirement, you could leverage log4net.Util.PatternString and use the env conversion pattern to retrieve the environment variable (WEBROOT_PATH) suggested by David Ebbo. You need to change your path as follows:

<file type="log4net.Util.PatternString" value="%env{WEBROOT_PATH}\\App_Data\\Logs\\WebJobLog.log" />

Additionally, you could create your FileAppender programmatically, for this approach you could refer to this issue. Moreover, you could check the build-in logging for webjobs here.

1
votes

You should avoid hard coding relative assumptions about where the WebJobs is deployed.

If your goal is to get to the APP_DATA folder, you can look at the WEBROOT_PATH environment variable, which points to d:\home\site\wwwroot, and then combine it with APP_DATA.