Configure azure diagnostics on existing web app - azure

I have an existing App which has logging enabled on Log4net , which runs on VS 2012.
The logs are sent on a database table, I woiuld like to move it to use azure tables.
I have added the following lines in web.config as well as downloaded the Azure SDK.
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
What else do I need to do to start logging using azure tables ?
For a start is there a way I can run the website on local and configure things to be logged on azure table on the storage emulator.

You do not need to add to the web.config of your web app. To enable logging to an Azure Storage Table, go to the configure page of your web app in the Azure Management portal at https://manage.windowsazure.com. (The preview portal currently doesn't support this).
In the application diagnostics section, set application logging (table storage) to ON, specify your logging level, and then click the manage table storage button to specify the storage account and table name you want to write logs to. Then click the SAVE button at the bottom of the page and you're done.

Related

How to attach diff Azure storage tables to save elmah logs

I have installed elmah to my asp.net mvc application using below nuget package
<package id="Elmah.AzureTableStorage" version="1.0.0.0" targetFramework="net452" />
Also i have configured Azure storage connection to store logs in to Azure tables as below
<add name="ElmahAzureTableStorage" connectionString="{my connection string}" />
Now it's storing all error logs in Elmah table in Azure table storage , I would like to keep local & live error logs in different folder so is there any way i can define to use which table according to diff local & live env (web.config & web.release.config)?
You should use web.config transformation for this, like described here: Use multiple logs for different environments. The article uses elmah.io as an example, but the approach is similar when using Azure table storage.
Basically, you need to configure the local environment in your web.config and "override" the ElmahAzureTableStorage setting in web.release.config like this:
<add
key="ElmahAzureTableStorage"
value="{my live connection string}"
xdt:Transform="SetAttributes"
xdt:Locator="Match(key)"/>

Disable RapidFail Protection in WebApp

I have recently migrated from Azure Cloud Service to Azure Web App. Earlier I use to Disable the rapidFailProtection from my Webrole class. After the migration to Web App, I have remove the webrole class and added the code of rapidFail in the Application startup routine of the global.asax file. But it gave an error:
role discovery data is unavailable
at the following line:
Dim mainSite = serverManager.Sites(RoleEnvironment.CurrentRoleInstance.Id + "_Web")
How can I achieve the same functionality for my Azure Web App?
How can I achieve the same functionality for my Azure Web App?
As far as I know, the rapidFailProtection is a application pool setting which you could set it in the ApplicationHost.config file in app service.
So if you want to set the rapidFailProtection to false in the azure web app, I suggest you could try to use XML Document Transformation (XDT) declarations to transform the ApplicationHost.config file in your web app in Azure App Service.
I suggest you could try below steps to add the XDT file to your web app to change the ApplicationHost.config settings.
1.Access the KUDU console.Find the Advanced Tools in DEVELOPMENT TOOLS click go.
2.Click dubug console's cmd.
3.Locate the D:\home\site and add below xdt file.
Notice: Change the name as your web app service name
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<system.applicationHost>
<applicationPools>
<add name="testforapppool" xdt:Locator="Match(name)">
<failure rapidFailProtection="false" xdt:Transform="InsertBefore(/configuration/system.applicationHost/applicationPools/add[(#name='testforapppool')]/*[1])" />
</add>
<add name="~1testforapppool" xdt:Locator="Match(name)">
<failure rapidFailProtection="false" xdt:Transform="InsertBefore(/configuration/system.applicationHost/applicationPools/add[(#name='~1testforapppool')]/*[1])" />
</add>
</applicationPools>
</system.applicationHost>
</configuration>
Image:
Besides, you could also install Site Extension called IIS Manager which lets you very easily create XDT files simply by editing your applicationhost.config.
More details, you could refer to this article:
Azure App Service web app advanced config and extensions
Xdt transform samples

Azure Cloud Service Logging and viewing whats happening

I have an azure cloud service and I am struggling and feel I have exhausted all avenues on trying to identify what is going wrong. When I try hit one of the actions I get an internal server 500 however I can't see no stack trace of this at all!
I have enabled diagnostics via the setting:
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.4.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics" />
</listeners>
</trace>
</system.diagnostics>
And within azure portal I have setup the connection string which I am monitoring via Azure Management Studio. However, for the life of me I cannot see whats going wrong.
I have remoted onto the box to and tried it locally and nothing is seen in the event log, no exception.
What I have done, is change the setting via portal to another value and back to the original and for some reason that seems to make the app work. However, this workaround is unacceptable and for future reference I would like to see the error it is throwing.
Cheers, DS.
From my experience with Cloud Services, I'd advice you to set up a free NewRelic account, add the NewRelic package to your Cloud Service, and check NewRelic's findings.
It's extremely helpful and it will dig up and tell you exactly in which part of your code is the error and the stack trace.
Debugging Apps in the Cloud without something like NewRelic or AppInsights feels almost like shooting in the dark.

Trace messages from Website not appearing in Azure Diagnostics

I have an API deployed as an Azure Website (not a worker role). The code for the site has Trace statements dotted through it that I would like to capture in an Azure Table via the Azure Diagnostics.
I'm using Trace.TraceError, Trace.TraceInformation, etc.
I've followed the instructions here, which essentially say that all that is required is to flick the switch in the management portal and set a location for Application Diagnostics: https://azure.microsoft.com/en-us/documentation/articles/web-sites-enable-diagnostic-log/
I have ensured that the Microsoft.WindowsAzure.Diagnostics reference is added to the project, and I have also tried adding the following to the Web.config (even though the instructions don't say this is necessary):
<system.diagnostics>
<trace autoflush="true" indentsize="4" >
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=2.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" name="AzureDiagnostics" />
</listeners>
</trace>
</system.diagnostics>
Despite this, the only output I get to the Azure Blob and/or Table (that I specified in the portal) is the following:
24/06/2015 14:02:49 AlasdairOTCDev Verbose SnapshotHelper::RestoreSnapshotInternal SUCCESS - process 11284 -1
24/06/2015 14:02:48 AlasdairOTCDev Verbose SnapshotHelper::RestoreSnapshotInternal SUCCESS - File.Copy 11284 -1
Trace levels are set to Verbose in the portal.
What am I doing wrong, and how can I debug this?
Many thanks for any assistance that can be provided as I'm rapidly running out of hair to pull out...
It turns out the root of the problem was with our build.
There was an issue where our build script was not compiling the TRACE symbol. Builds compiled locally did include this (which is why it all appeared to work locally) but when we built and deployed to Azure it was being missed out.
Without the TRACE symbol, none of the logging statements were activated.
You don't need the reference to Microsoft.WindowsAzure.Diagnostics in your project. That is for Cloud Services and the article you referenced does not mention it since it is for Azure Web Apps (formerly Websites).
Assuming you are using an Azure Web App (not a cloud service web role), then you have to use the current Azure Management portal at https://manage.windowsazure.com if you want to configure your web app to store application diagnostics to an Azure Storage Table or Azure Storage Blob Container. In the configure page for the web app, your configuration should look like this for a table storage.
(Currently, the preview portal at https://portal.azure.com only lets you configure application diagnostics logging using the web app's file system)
For anyone who still encounters this problem, besides for the excellent answers given on this page (enable tracing on azure, and making sure TRACE is set to true in your build), make sure you actually flush the traces!
In your code you need something like this:
System.Diagnostics.Trace.TraceError("Can you see me?");
System.Diagnostics.Trace.Flush();
Or
System.Diagnostics.Trace.AutoFlush = true;
System.Diagnostics.Trace.TraceError("Can you see me?");

Azure Cloud Service and Persistent Configuration Settings

I'm building a Node.js app to be deployed as an Azure Cloud Service Worker Role.
As a good practice, I like keep all sensitive info (API keys, etc) out of my repos. My usual solution for this is to add sensitive info as environment variables, and have my app access those.
In the (relatively new) Azure Websites, this is easily done through the "app settings" section of the "Configure" tab. Add new settings and grab them in Node.js with process.env.<setting key>. These settings persist across updates and deployments.
In Azure Cloud Services, however, this doesn't seem to be the case. I've added "Configuration Settings" to my ServiceConfiguration.Cloud.cscfg:
<ConfigurationSettings>
<Setting name="API_KEY_1" value="" />
<Setting name="API_KEY_2" value="" />
</ConfigurationSettings>
...and my ServiceDefinition.csdef:
<ConfigurationSettings>
<Setting name="API_KEY_1" />
<Setting name="API_KEY_2" />
</ConfigurationSettings>
When I deployed, these settings became editable through the web portal, and I added their values.
When I redeploy, however, the settings are overwritten. The only way I can see to keep their appropriate values is to add the values to the .cscfg. But that would mean committing this info into my repo.
Is there a solution I'm missing?
General approach I would use it to put the settings into a storage account and then have a cscfg setting that targets the storage account. On startup, you can read the values out of the storage account and keep them locally in whatever manner you need them.
That aside, if you wish to continue using the cscfg file, you can keep multiple copies of that file and just deploy with the correct version.

Resources