I deployed a webjob onto Azure (under the home\site\wwwroot\App_Data\jobs\triggered
directory). This application contains NLog-logging which is configured in the appsettings and uses environment-variable for the logfile-path:
"NLog": {
"throwConfigExceptions": true,
"targets": {
"logfile": {
"type": "File",
"fileName": "${environment:variable=DEPLOYMENT_SOURCE}\\LogFiles\\timer-${shortdate}.log",
"layout": "${message} "
},
The DEPLOYMENT_SOURCE
- Environment-variable contains a valid path when displaying it in kudu:
echo %DEPLOYMENT_SOURCE%
C:\home
But Nlog does not seem to be able to resolve that environment var. When enabling Trace-Log I receive the following error message:
Debug Creating file appender: C:\LogFiles\timer-2020-11-13.log
Trace Opening C:\LogFiles\timer-2020-11-13.log with allowFileSharedWriting=False
Error FileTarget(Name=logfile): Failed write to file 'C:\LogFiles\timer-2020-11-13.log'. Exception: > System.UnauthorizedAccessException: Access to the path 'C:\LogFiles\timer-2020-11-13.log' is denied.
So it seems like DEPLOYMENT_SOURCE is simply an empty string.
When testing this locally though with a valid Windows-Env like %TEMP%
everything works fine.
What has to be done to access Azure-Environments in Dotnetcoreapps/NLog-Config?
DEPLOYMENT_SOURCE
containsC:/
but not the expectedC:\home
, Maybe an environment issue? Thought log-files should be placed hereD:/Home/LogFiles/Application
that should match%HOME%\LogFiles\Application
or${environment:HOME}/LogFiles/Application/timer-${shortdate}.log
. Anyway know little about Azure, but know that NLog has no issue with environment-variables. – Rolf Kristensen"${environment}
. E.g."fileName": "c\\logs\\LogFiles\\timer-${shortdate}.log","layout": "${message} env='${environment:variable=DEPLOYMENT_SOURCE}'"
– JulianEnvironment.GetEnvironmentVariable
, so nothing special at all – Julian