.NET NLog retreive local directory - nlog

The following retrieves the temp directory :
${tempdir}
How do I retrieve the local directory ?
I am talking about the configuration file used to setup the log
environment.

Maybe you are looking for one of these:
${BaseDir}
${CurrentDir}
${ProcessDir}
${AspNet-AppBasePath}

Related

Possible to edit web.config of cloud app deployed on windows Azure without redeploying app?

I would like to add rewrite URL code on azure web app's web.config without redeploying the whole app again. for this I am using 'app service editor' and 'kudu- debug console' for editing the web.config, first I cant save the file and gives me error.
after some search I found that under APP SETTING KEY value should be 0 instead 1
edited the value 1 to 0 and save the APP SETTING KEY, after that I am able to edited the config file, in order to test the code again I changed the value 0 to 1 and save the setting. but when I refresh the file which is opened in editor or kudu the pasted code disappeared, the site is connected with automatic azure deployment pipeline
How I can edited the web.config file without redeploying the app again.
Yes, it's possible to make changes without redeploying the app.
Some details:
Check Run the package document and we can find:
1.The zip package won't be extracted to D:\home\site\wwwroot, instead it will be uploaded directly to D:\home\data\SitePackages.
2.A packagename.txt which contains the name of the ZIP package to load at runtime will be created in the same directory.
3.App Service mounts the uploaded package as the read-only wwwroot directory and runs the app directly from that mounted directory. (That's why we can't edit the read-only wwwroot directory directly)
So my workaround is:
1.Navigate to D:\home\data\SitePackages in via kudu- debug console:
Download the zip(In my case it's 20200929072235.zip) which represents your deployed app, extract this zip file and do some changes to web.config file.
2.Zip those files(choose those files and right-click...) into a childtest.zip, please follow my steps carefully here!!! The folder structure of Run-from-package is a bit strange!!!
3.Then zip the childtest.zip into parenttest.zip(When uploading the xx.zip, the kudu always automatically extra them. So we have to zip the childtest.zip into parenttest.zip first)
4.Drag and drop local parenttest.zip into online SitePackages folder in kudu-debug console and we can get a childtest.zip now:
5.Modify the packagename.txt, change the content from 20200929072235.zip to childtest.zip and Save:
Done~
Check and test:
Now let's open App Service Editor to check the changes:
In addition: Though it answers the original question, I recommend using other deployment methods(web deploy...) as a workaround. It could be much easier~

Possible to create file in sources directory on Azure DevOps during build

I have a node script which needs to create a file in the root directory of my application before it builds the file.
The data this file will contain is specific to each build that gets triggered, however, I'm having no luck on Azure DevOps in this regards.
For the writing of the file I'm using fs.writeFile(...), something similar to this:
fs.writeFile(targetPath, file, function(err) { // removed for brevity });
however, this throws an expection:
[Error: ENOENT: no such file or directory, open '/home/vsts/work/1/s/data-file.json']
Locally this works, I'm assuming this has got to do with permissions, however, I tried adding a blank version of this file to my project, however, it still throws this exception.
Possible to create file in sources directory on Azure DevOps during
build
The answer is Yes. This is fully supported scenario in Azure Devops Service if you're using Microsoft ubuntu-hosted agent.
If you met this issue when using microsoft-hosted agent, I think this issue is more related to one path issue. Please check:
The function where the error no such file or directory comes. Apart from the fs.writeFile function, do you also use fs.readFile in the xx.js file? If so, you should make sure the two paths are same.
The structure of your source files and your real requirements. According to your question you want to create it in Source directory /home/vsts/work/1/s, but the first line indicates that you actually want to create file in root directory of my application.
1).If you want to create file in source directory /home/vsts/work/1/s:
In your js file: Use something targetpath like './data-file.json'. And make sure you're running command node xx.js from source directory. (Leaving CMD task/PS task/Bash task's working directory blank!!!)
2).If you want to do that in root of application folder like /home/vsts/work/1/s/MyApp:
In your js file: Use __dirname like fs.writeFile(__dirname + '/data-file.json', file, function(err) { // removed for brevity }); and fs.readFile(__dirname + '/data-file.json',...).

Google Cloud Natural Language Example

I have followed the getting started page closely.
https://cloud.google.com/natural-language/docs/reference/libraries#client-libraries-install-php
The example code has the following: $projectId = 'YOUR_PROJECT_ID';
I fill in my project id taken from the json file and the Google console--e.g. "$projectID = 'myproject-197218'" and I always get a fatal error with "Permission Denied."
I have set the env variable, run composer to install the library. And, I created the Google json file. I am running the example in PHP code.
I am running the code on my local server (xampp).
I figured out my problem. The Google Cloud json file was stored on my drive d:, so in the env variable I referenced it as 'GOOGLE_APPLICATION_CREDENTIALS= d:\xampp\htdocs\googapi\mproj.json', it did not work; when I moved it to the root of the c: drive and referenced it there (GOOGLE_APPLICATION_CREDENTIALS=c:proj.json), it worked fine.
Are you sure that the ID of your project is that one? I'm working in Google Cloud and I cannot see this project ID in our database, but if I type "my-project-197218" with a "-" between "my" and "project" I am able to find one project. please, to make sure that this is your correct project ID, run this command in your Google Cloud Shell to get the default project ID:
gcloud config list --format 'value(core.project)' 2>/dev/null

IIS6 bat file - Home Directory

How do I get the Root/Home Directory of a website in IIS6 using a batch file??
My Scenario:
I am creating a tool to summarise and report of sites in IIS. I am using batch files and running iisweb /query to get all the sites then looping over the results and using iisvdir /query "Website Name" to get the virtual directories.
However it has to be backwards compatible with IIS6 and I am having trouble getting the Home Directory of the site.
I don't think you can do this directly from a batch file, but you should be able to do it from a vbscript which you can call from a batch file.
The trick is to use the IIS WMI provider which gives you access to the IIS metabase. For example, the script below should echo the name and path of every virtual directory on the local server.
set provider = GetObject("winmgmts://localhost/root/MicrosoftIISv2")
set results = provider.ExecQuery("SELECT Name,Path from IISWebVirtualDirSetting")
for each item in results
WScript.Echo item.Name
WScript.Echo item.Path
next
If you saved this script as iispaths.vbs (just as an example), you could then call it from a batch file with:
cscript //nologo iispaths.vbs
Unfortunately I don't have access to a machine with IIS6, so I am unable to test this at the moment, but if you have any problems getting it to work, feel free to let me know in the comments and I'll do my best to fix the issue.
I don't have a IIS6 server, however, through some searching, I found that:
IIS6 uses %SystemRoot%\system32\inetsrv\MetaBase.xml and %SystemRoot%\system32\inetsrv\MBSchema.xml for storing configuration (The IIS Metabase (IIS 6.0));
If your server isn't changing home-directories too often, those xml should be updated;
using a command line parser (like xmlstartlet), you can extract Path property from IIsWebVirtualDir node (according Metabase Structure), using XPath.
With xmlstartlet, a command like below, would output root path:
xml sel -t -v "//IIsWebVirtualDir[#Location='/LM/W3SVC/1/ROOT']/#Path" "%SystemRoot%\system32\inetsrv\MetaBase.xml"
Maybe schema needs to be corrected.
This can be a command line approach. I can't test it as I don't have any IIS6 server neither I can get any MetaBase.xml sample.

Snap configuration file

How would I correctly use configuration file in Snap?
At the moment, I hard code DB host and DB name. If I wanted to put it in a file within projectroot/config directory, how would I make it available within a handler or within app init function?
It is mentioned briefly in snaplets tutorial that configurator library can be used but there was no explanation of how to actually use it.
Thanks.
Just call getSnapletUserConfig which returns a Config. Then use functions from configurator to get the information you need. Look at snaplet-postgresql-simple's use of config files for a working example.
The config file defaults to devel.cfg in the current snaplet file path. So if you are using getSnapletUserConfig in your top-level application, then the config file will be in your project root. Otherwise it will be in snaplets/foo where "foo" is the name of whatever snaplet you are in.

Resources