I knew that we can use RoleEnvironment.IsAvailable
to check if code is running in Web/Worker Role. How about Azure Websites?
I tried the above RoleEnvironment code but it always returns false. I need to run some configuration code in Application_Start
so I cannot depend on the request stuff.
Any help is appreciated.
The best way I've come across to determine if you're running on an Azure Website is to check for the presence of an environment variable specific to Azure Websites like WEBSITE_SITE_NAME . You could check this first, and if the variable does not exist, proceed with the RoleEnvironment.
Azure Monitor provides base-level infrastructure metrics and logs for most services in Azure. You can interact with the metrics in several ways, including charting them in Azure portal, accessing them through the REST API, or querying them using PowerShell or CLI.
On the portal, click on “Log Stream” immediately below “App Services log” and you'll see the log messages in real time.
We are able to generate the logs and they are in the path /home/logfiles/applications.
This is actually very easy simply check for existence of this environment variable: WEBSITE_SITE_NAME
.
!String.IsNullOrEmpty(Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME"))
The content for this will be the name of your site.
To see more environment variable that you have under your site go to the following link: https://{sitename}.scm.azurewebsites.net/Env
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With