How can I change TelemetryChannel properties for Application Insights? - azure-application-insights

Microsoft provides documentation of many settings that can be set for the TelemetryChannel class in Application Insights.
But I can't find any explanation of how these settings can be set.
Setting them in the ApplicationInsights.config file like this does not work for my web application:
<TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel">
<DataUploadIntervalInSeconds>1</DataUploadIntervalInSeconds>
<MaxTelemetryBufferCapacity>1</MaxTelemetryBufferCapacity>
</TelemetryChannel>
I simply cannot seem to influence my web app to honor these settings.
How can these settings be adjusted?

The sample config in below git spark the idea of usage. You have to use Profiles & set these settings.
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
<ActiveProfile>Production</ActiveProfile>
<Profiles>
<Profile name="Production">
<!-- <ServerAnalytics> controls Application Insights Telemetry SDK settings. -->
<ServerAnalytics enabled="true">
<!-- The frequency in seconds with which the SDK uploads data to Application Insights. -->
<DataUploadIntervalInSeconds>60</DataUploadIntervalInSeconds>
</Profile>
</Profiles>
</ApplicationInsights>
https://github.com/postsharp/ApplicationInsightsExample/blob/master/ApplicationInsightsExample/ApplicationInsights.config

Related

ASP.NET how to set a variable in web.config during publising an app

I have an ASP.NET application and I would like to set a variable during publishing the application depending on the environment (like production, quality, etc....)
I have created a variable in the web.config file in the <appSettings /> section inside <configuration /> section like this:
<add key="RunningEnvironment" value="dev"/>
I have two profiles when deploying dev and prod
How can I set the RunningEnvironment variable in the web.config depending on the profile I choose when deploying?
Take a look at web.config transformations.
In your Web.Production.Config for production environment set this:
<add xdt:Transform="Replace" xdt:Locator="Match(key)" key="RunningEnvironment" value="prod"/>
A handy tip you better know is Preview Transform dropdown menu option on Web.<ConfigurationName>.Config file in Visual Studio. There you will see all the changes that are going to take effect.

Azure Application Insights and Web Site projects

Is it possible to add Application Insights to a Web Site project type?
In Visual Studio, the following context menu is available for Web Application projects but is missing for Web Site projects.
You should be able to instrument a Web Site project with Application Insights manually. Here are the instructions.
Just want to share what I ended up with doing. First of all, it seems to work like a charm.
The Application Insight is implemented as an ASP.NET Module, so in order to hook it up for Web Site project you need to do the following:
Add Microsoft.ApplicationInsights.Web NuGet package
Register AI module in web.config
<modules runAllManagedModulesForAllRequests="true">
<remove name="ApplicationInsightsWebTracking" />
<add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
</modules>
Make sure you have ApplicationInsights.config in Web Site base directory (along with web.config) - it defines which telemetry you going to be collecting

Windows Azure and web.config settings

I'm new to Windows Azure and just created my first "Web Site". Very easy and running well. 1 question though...
Does Azure ignore and/or override some or all settings that I have configured in my web.config file?
As a simple example, I have the following in my web.config:
<system.webServer>
<defaultDocument enabled="true">
<files>
<clear />
<add value="index.html" />
</files>
</defaultDocument>
</system.webServer>
But I still see many possible default documents listed on the Configure tab for my site.
It got me wondering what other settings it is ignoring.
Thanks.
If you have a <clear/> line, I would not expect any of the default docs that you see in the Azure portal to actually be effective. What the Azure portal shows is what ends up going in ApplicationHost.config, which your web.config overrides.
Are you saying that you still see the Azure portal values being effective at runtime? That would be puzzling.
IIS in Windows lists several common default documents when you manage a site(home.html, index.php, etc). What you have listed in your web.config is not the list of possible default documents, it is the exact default document for your application. Azure is showing you common default documents in the configuration manager and will override your web.config if you choose something different.

Are ASP.NET Health Monitoring and ELMAH alternatives of each other?

I was going to use ELMAH for our ultimate automatic error logging but recently realized that ASP.NET Health Monitoring does a same work (perhaps). Now I want to know (please) if they are alternatives of each other just like log4net and entlib?
ELMAH is for error monitoring, pure and simple. Easy to see the errors via a readout, RSS feeds, etc. Health monitoring is more of a full instrumentation solution.
Want the easy answer?
Look at how to setup Health Monitoring
Look at how to setup ELMAH
ELMAH is a very quick pluggable solution for error monitoring it has a very specific task (that is does beautifully). Health Monitoring is more of the shotgun see/monitor everything approach and involves much more setup work. Oh yeah, need to make a change? It's open source, grab it, change it as you like.
I have not used Health Monitoring in ASP.NET but I have used ELMAH and it is simply amazing. It literally takes only 2 minutes to setup and then you can see all the errors. There are also so many options to display the errors. Try out ELMAH you are going to love it.
ASP.NET Health Monitoring will automatically generate messages for events like app domain startup and shutdown and heartbeats and many other information about the web application. Logging frameworks don't support such features, but you can route the Health Monitoring system events to your logging framework of choice. Some frameworks even support this out of the box, such as CuttingEdge.Logging. Here is an configuration example of a CuttingEdge.Logging where the health events are forwarded to a logging provider:
<?xml version="1.0"?>
<configuration>
<configSections>
<section name="logging"
type="CuttingEdge.Logging.LoggingSection, CuttingEdge.Logging" />
</configSections>
<system.web>
<healthMonitoring heartbeatInterval="0" enabled="true">
<providers>
<!-- We're configuring the web event provider here. -->
<add name="LoggingWebEventProvider"
type="CuttingEdge.Logging.Web.LoggingWebEventProvider, CuttingEdge.Logging"
loggingProvider="DebugLogger" />
</providers>
<rules>
<add name="Custom Event Provider"
eventName="All Events"
provider="LoggingWebEventProvider"
profile="Default" />
</rules>
</healthMonitoring>
</system.web>
<logging defaultProvider="DebugLogger">
<providers>
<!-- Configure your favorite provider here. -->
<add name="DebugLogger"
type="CuttingEdge.Logging.DebugLoggingProvider, CuttingEdge.Logging"
description="Debug logging provider"
threshold="Debug" />
</providers>
</logging>
</configuration>

Setting variables in web config for web service consumption

I did a couple google searches about this and am not finding anything, so I thought I'd ask here.
I'm working on our internal CMS and I noticed that we're getting live data back when doing debugging because of our web services instead of the dev data that I wanted. It doesn't do this on our dev CMS website, but we're trying to do all our development on localhost. Is there any way to set up an environment variable in our web config for the URL so that the CMS points to the dev database instead of live database that is referenced in the wsdl files?
You can use the appSettings portion of the web config to for configuration information.
In the configuration section of the Web.config you will find the appSettings section:
<appSettings>
<add key="Key" value="Some Value"/>
</appSettings>
In code you can read in the value like this:
var someValue = ConfigurationManager.AppSettings["Key"];
+1 for Dan's method of storing the URL. To use this URL at runtime just update the URL property of your web service proxy object with the value from your web.config.
MyClientClass o = new MyClientClass();
o.Url = varFromWebConfig;
o.MyWebMethod();
Actually, one of my coworkers suggested an alternate way of solving this issue which seems even better to me: fixing it server-side, rather than client side like I've been trying and has been suggested here. His suggestion was to create a subdomain in IIS on all of our servers that points to the web service folder and then put host files for the appropriate web server on my local machine. This seems like the ideal solution to me since it wouldn't require changing all the current web service proxy objects like the client side solution would, just the web service consumption within App_WebReferences.
YES!!! USE Web.config transforms
Web.config contains the configuration that will run in your IDE while debugging:
<configuration>
<appSettings>
<add key="Service.Name" value="http://debugserverURI/Service.asmx"/>
</appSettings>
</configuration>
On publish in "Release" mode, transforms in Web.Release.config will be applied:
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<!--point to production server -->
<add key="Service.Name" value="http://PRODUCTIONserverURI/Service.asmx"
xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
</appSettings>
</configuration>
You can do the same for Web.[whatever_build_you_want].config, if you support both test and prod servers.

Resources