ASP.NET web siteniz için Uygulama Analizler yapılandırma

Bu yordam, ASP.NET web uygulamanızı Azure İzleyici hizmetinin Uygulama Analizler özelliğine telemetri gönderecek şekilde yapılandırılır. Şirket içinde veya bulutta kendi IIS sunucularınızda barındırılan ASP.NET uygulamalar için çalışır.

Not

Aşağıdaki belgeler, Uygulama Analizler klasik API'sine dayanır. Uygulama Analizler için uzun vadeli plan, OpenTelemetry kullanarak veri toplamaktır. Daha fazla bilgi için bkz . .NET, Node.js, Python ve Java uygulamaları için Azure İzleyici OpenTelemetry'yi etkinleştirme.

Not

31 Mart 2025’te izleme anahtarı alımı desteği sona erecektir. İzleme anahtarı alımı çalışmaya devam edecek, ancak artık özellik için güncelleştirme veya destek sağlamayacağız. Yeni özelliklerden yararlanmak için bağlantı dizesi geçiş.

Önkoşullar

Application Insights’ı ASP.NET web sitenize eklemek için şunu yapmanız gerekir:

Önemli

İzleme tuşları üzerinde bağlantı dizesi öneririz. Yeni Azure bölgeleri, izleme anahtarları yerine bağlantı dizesi kullanımını gerektirir.

bağlantı dizesi, telemetri verilerinizle ilişkilendirmek istediğiniz kaynağı tanımlar. Ayrıca, kaynağınızın telemetriniz için hedef olarak kullanacağı uç noktaları değiştirmenize de olanak tanır. bağlantı dizesi kopyalayıp uygulamanızın koduna veya "APPLICATIONINSIGHTS_CONNECTION_STRING" ortam değişkenine eklemeniz gerekir.

Temel ASP.NET web uygulaması oluşturma

  1. Visual Studio 2019'yu açın.
  2. Dosya>Yeni>Proje’yi seçin.
  3. ASP.NET Web Uygulaması(.NET Framework) C# öğesini seçin.
  4. Bir proje adı girin ve Oluştur'u seçin.
  5. MVC>Oluştur'u seçin.

Uygulama Analizler otomatik olarak ekleme

Bu bölüm, şablon tabanlı bir ASP.NET web uygulamasına Uygulama Analizler otomatik olarak ekleme işleminde size yol gösterir. Visual Studio'da ASP.NET web uygulaması projenizin içinden:

  1. Proje>Uygulama Ekle Analizler Telemetri>Uygulaması Analizler Sdk 'sı (yerel)>Sonraki>Son Kapanış'ı> seçin.

  2. Application Analizler.config dosyasını açın.

  3. Kapanış </ApplicationInsights> etiketinden önce, Uygulama Analizler kaynağınız için bağlantı dizesi içeren bir satır ekleyin. yeni oluşturulan Uygulama Analizler kaynağının genel bakış bölmesinde bağlantı dizesi bulun.

    <ConnectionString>Copy connection string from Application Insights Resource Overview</ConnectionString>
    
  4. NuGet Paketlerini> Proje Yönet Güncelleştirmeler'i seçin.> Ardından her Microsoft.ApplicationInsights NuGet paketini en son kararlı sürüme güncelleştirin.

  5. IIS Express'i seçerek uygulamanızı çalıştırın. Temel bir ASP.NET uygulaması açılır. Sitedeki sayfalara göz atarken, telemetri Uygulama Analizler'ne gönderilir.

Uygulama Analizler el ile ekleme

Bu bölüm, şablon tabanlı bir ASP.NET web uygulamasına Uygulama Analizler el ile ekleme işleminde size yol gösterir. Bu bölümde, ASP.NET Framework için standart MVC web uygulaması şablonunu temel alan bir web uygulaması kullandığınız varsayılır.

  1. Projenize aşağıdaki NuGet paketlerini ve bunların bağımlılıklarını ekleyin:

  2. Bazı durumlarda Application Analizler.config dosyası sizin için otomatik olarak oluşturulur. Dosya zaten varsa, 4. adıma geçin.

    Otomatik olarak oluşturulmazsa kendiniz oluşturmanız gerekir. bir ASP.NET uygulamasının kök dizininde Application Analizler.config adlı yeni bir dosya oluşturun.

  3. Aşağıdaki XML yapılandırmasını yeni oluşturduğunuz dosyaya kopyalayın:

    <?xml version="1.0" encoding="utf-8"?>
    <ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
      <TelemetryInitializers>
        <Add Type="Microsoft.ApplicationInsights.DependencyCollector.HttpDependenciesParsingTelemetryInitializer, Microsoft.AI.DependencyCollector" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureRoleEnvironmentTelemetryInitializer, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.BuildInfoConfigComponentVersionTelemetryInitializer, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.Web.WebTestTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.SyntheticUserAgentTelemetryInitializer, Microsoft.AI.Web">
          <!-- Extended list of bots:
                search|spider|crawl|Bot|Monitor|BrowserMob|BingPreview|PagePeeker|WebThumb|URL2PNG|ZooShot|GomezA|Google SketchUp|Read Later|KTXN|KHTE|Keynote|Pingdom|AlwaysOn|zao|borg|oegp|silk|Xenu|zeal|NING|htdig|lycos|slurp|teoma|voila|yahoo|Sogou|CiBra|Nutch|Java|JNLP|Daumoa|Genieo|ichiro|larbin|pompos|Scrapy|snappy|speedy|vortex|favicon|indexer|Riddler|scooter|scraper|scrubby|WhatWeb|WinHTTP|voyager|archiver|Icarus6j|mogimogi|Netvibes|altavista|charlotte|findlinks|Retreiver|TLSProber|WordPress|wsr-agent|http client|Python-urllib|AppEngine-Google|semanticdiscovery|facebookexternalhit|web/snippet|Google-HTTP-Java-Client-->
          <Filters>search|spider|crawl|Bot|Monitor|AlwaysOn</Filters>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.ClientIpHeaderTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.AzureAppServiceRoleNameFromHostNameHeaderInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.OperationNameTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.OperationCorrelationTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.UserTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.AuthenticatedUserIdTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.AccountIdTelemetryInitializer, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.SessionTelemetryInitializer, Microsoft.AI.Web" />
      </TelemetryInitializers>
      <TelemetryModules>
        <Add Type="Microsoft.ApplicationInsights.DependencyCollector.DependencyTrackingTelemetryModule, Microsoft.AI.DependencyCollector">
          <ExcludeComponentCorrelationHttpHeadersOnDomains>
            <!-- 
            Requests to the following hostnames will not be modified by adding correlation headers.         
            Add entries here to exclude additional hostnames.
            NOTE: this configuration will be lost upon NuGet upgrade.
            -->
            <Add>core.windows.net</Add>
            <Add>core.chinacloudapi.cn</Add>
            <Add>core.cloudapi.de</Add>
            <Add>core.usgovcloudapi.net</Add>
          </ExcludeComponentCorrelationHttpHeadersOnDomains>
          <IncludeDiagnosticSourceActivities>
            <Add>Microsoft.Azure.EventHubs</Add>
            <Add>Azure.Messaging.ServiceBus</Add>
          </IncludeDiagnosticSourceActivities>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.PerformanceCollectorModule, Microsoft.AI.PerfCounterCollector">
          <!--
          Use the following syntax here to collect additional performance counters:
    
          <Counters>
            <Add PerformanceCounter="\Process(??APP_WIN32_PROC??)\Handle Count" ReportAs="Process handle count" />
            ...
          </Counters>
    
          PerformanceCounter must be either \CategoryName(InstanceName)\CounterName or \CategoryName\CounterName
    
          NOTE: performance counters configuration will be lost upon NuGet upgrade.
    
          The following placeholders are supported as InstanceName:
            ??APP_WIN32_PROC?? - instance name of the application process  for Win32 counters.
            ??APP_W3SVC_PROC?? - instance name of the application IIS worker process for IIS/ASP.NET counters.
            ??APP_CLR_PROC?? - instance name of the application CLR process for .NET counters.
          -->
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryModule, Microsoft.AI.PerfCounterCollector" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AppServicesHeartbeatTelemetryModule, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.AzureInstanceMetadataTelemetryModule, Microsoft.AI.WindowsServer">
          <!--
          Remove individual fields collected here by adding them to the ApplicationInsighs.HeartbeatProvider 
          with the following syntax:
    
          <Add Type="Microsoft.ApplicationInsights.Extensibility.Implementation.Tracing.DiagnosticsTelemetryModule, Microsoft.ApplicationInsights">
            <ExcludedHeartbeatProperties>
              <Add>osType</Add>
              <Add>location</Add>
              <Add>name</Add>
              <Add>offer</Add>
              <Add>platformFaultDomain</Add>
              <Add>platformUpdateDomain</Add>
              <Add>publisher</Add>
              <Add>sku</Add>
              <Add>version</Add>
              <Add>vmId</Add>
              <Add>vmSize</Add>
              <Add>subscriptionId</Add>
              <Add>resourceGroupName</Add>
              <Add>placementGroupId</Add>
              <Add>tags</Add>
              <Add>vmScaleSetName</Add>
            </ExcludedHeartbeatProperties>
          </Add>
    
          NOTE: exclusions will be lost upon upgrade.
          -->
        </Add>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.DeveloperModeWithDebuggerAttachedTelemetryModule, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnhandledExceptionTelemetryModule, Microsoft.AI.WindowsServer" />
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.UnobservedExceptionTelemetryModule, Microsoft.AI.WindowsServer">
          <!--</Add>
        <Add Type="Microsoft.ApplicationInsights.WindowsServer.FirstChanceExceptionStatisticsTelemetryModule, Microsoft.AI.WindowsServer">-->
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.RequestTrackingTelemetryModule, Microsoft.AI.Web">
          <Handlers>
            <!-- 
            Add entries here to filter out additional handlers: 
    
            NOTE: handler configuration will be lost upon NuGet upgrade.
            -->
            <Add>Microsoft.VisualStudio.Web.PageInspector.Runtime.Tracing.RequestDataHttpHandler</Add>
            <Add>System.Web.StaticFileHandler</Add>
            <Add>System.Web.Handlers.AssemblyResourceLoader</Add>
            <Add>System.Web.Optimization.BundleHandler</Add>
            <Add>System.Web.Script.Services.ScriptHandlerFactory</Add>
            <Add>System.Web.Handlers.TraceHandler</Add>
            <Add>System.Web.Services.Discovery.DiscoveryRequestHandler</Add>
            <Add>System.Web.HttpDebugHandler</Add>
          </Handlers>
        </Add>
        <Add Type="Microsoft.ApplicationInsights.Web.ExceptionTrackingTelemetryModule, Microsoft.AI.Web" />
        <Add Type="Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule, Microsoft.AI.Web" />
      </TelemetryModules>
      <ApplicationIdProvider Type="Microsoft.ApplicationInsights.Extensibility.Implementation.ApplicationId.ApplicationInsightsApplicationIdProvider, Microsoft.ApplicationInsights" />
      <TelemetrySinks>
        <Add Name="default">
          <TelemetryProcessors>
            <Add Type="Microsoft.ApplicationInsights.Extensibility.PerfCounterCollector.QuickPulse.QuickPulseTelemetryProcessor, Microsoft.AI.PerfCounterCollector" />
            <Add Type="Microsoft.ApplicationInsights.Extensibility.AutocollectedMetricsExtractor, Microsoft.ApplicationInsights" />
            <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
              <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
              <ExcludedTypes>Event</ExcludedTypes>
            </Add>
            <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
              <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
              <IncludedTypes>Event</IncludedTypes>
            </Add>
            <!--
              Adjust the include and exclude examples to specify the desired semicolon-delimited types. (Dependency, Event, Exception, PageView, Request, Trace)
            -->
          </TelemetryProcessors>
          <TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel" />
        </Add>
      </TelemetrySinks>
      <!-- 
        Learn more about Application Insights configuration with ApplicationInsights.config here: 
        http://go.microsoft.com/fwlink/?LinkID=513840
      -->
      <ConnectionString>Copy connection string from Application Insights Resource Overview</ConnectionString>
    </ApplicationInsights>
    
  4. Kapanış </ApplicationInsights> etiketinden önce Uygulama Analizler kaynağınız için bağlantı dizesi ekleyin. bağlantı dizesi yeni oluşturulan Uygulama Analizler kaynağının genel bakış bölmesinde bulabilirsiniz.

    <ConnectionString>Copy connection string from Application Insights Resource Overview</ConnectionString>
    
  5. Projenizin Application Analizler.config dosyasıyla aynı düzeyde ErrorHandler adlı ve AiHandleErrorAttribute.cs adlı yeni bir C# dosyası içeren bir klasör oluşturun. Dosyanın içeriği şöyle görünür:

    using System;
    using System.Web.Mvc;
    using Microsoft.ApplicationInsights;
    
    namespace WebApplication10.ErrorHandler //namespace will vary based on your project name
    {
        [AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, Inherited = true, AllowMultiple = true)] 
        public class AiHandleErrorAttribute : HandleErrorAttribute
        {
            public override void OnException(ExceptionContext filterContext)
            {
                if (filterContext != null && filterContext.HttpContext != null && filterContext.Exception != null)
                {
                    //If customError is Off, then AI HTTPModule will report the exception
                    if (filterContext.HttpContext.IsCustomErrorEnabled)
                    {   
                        var ai = new TelemetryClient();
                        ai.TrackException(filterContext.Exception);
                    } 
                }
                base.OnException(filterContext);
            }
        }
    }
    
  6. App_Start klasöründe FilterConfig.cs dosyasını açın ve örnekle eşleşecek şekilde değiştirin:

    using System.Web;
    using System.Web.Mvc;
    
    namespace WebApplication10 //Namespace will vary based on project name
    {
        public class FilterConfig
        {
            public static void RegisterGlobalFilters(GlobalFilterCollection filters)
            {
                filters.Add(new ErrorHandler.AiHandleErrorAttribute());
            }
        }
    }
    
  7. Web.config zaten güncelleştirildiyse bu adımı atlayın. Aksi takdirde, dosyayı aşağıdaki gibi güncelleştirin:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      https://go.microsoft.com/fwlink/?LinkId=301880
      -->
    <configuration>
      <appSettings>
        <add key="webpages:Version" value="3.0.0.0" />
        <add key="webpages:Enabled" value="false" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.7.2" />
        <httpRuntime targetFramework="4.7.2" />
        <!-- Code added for Application Insights start -->
        <httpModules>
          <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" />
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" />
        </httpModules>
        <!-- Code added for Application Insights end -->
      </system.web>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" />
            <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-1.6.5135.21930" newVersion="1.6.5135.21930" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
          </dependentAssembly>
          <!-- Code added for Application Insights start -->
          <dependentAssembly>
            <assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
          </dependentAssembly>
          <!-- Code added for Application Insights end -->
        </assemblyBinding>
      </runtime>
      <system.codedom>
        <compilers>
          <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701" />
          <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
        </compilers>
      </system.codedom>
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <!-- Code added for Application Insights start -->
        <modules>
          <remove name="TelemetryCorrelationHttpModule" />
          <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="managedHandler" />
          <remove name="ApplicationInsightsWebTracking" />
          <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
        </modules>
        <!-- Code added for Application Insights end -->
      </system.webServer>
    </configuration>
    
    

Sunucu tarafı uygulama izlemeyi başarıyla yapılandırmış oldunuz. Web uygulamanızı çalıştırırsanız, telemetrinin Uygulama Analizler'de görünmeye başladığı görürsünüz.

İstemci tarafı izleme ekleme

Önceki bölümlerde, sunucu tarafı izlemeyi otomatik ve el ile yapılandırma yöntemleriyle ilgili yönergeler sağlanmıştır. İstemci tarafı izleme eklemek için istemci tarafı JavaScript SDK'sını kullanın. Sayfanın HTML'sinin kapanış </head> etiketinden önce bir JavaScript JavaScript (Web) SDK Yükleyici Betiği ekleyerek herhangi bir web sayfasının istemci tarafı işlemlerini izleyebilirsiniz.

JavaScript (Web) SDK Yükleyici Betiğini her HTML sayfasının üst bilgisine el ile eklemek mümkün olsa da, bunun yerine JavaScript (Web) SDK Yükleyici Betiğini birincil sayfaya eklemenizi öneririz. Bu eylem JavaScript (Web) SDK Yükleyici Betiğini bir sitenin tüm sayfalarına ekler.

Bu makaledeki şablon tabanlı ASP.NET MVC uygulaması için düzenlemeniz gereken dosya _Layout.cshtml'dir. Paylaşılan Görünümler>altında bulabilirsiniz. İstemci tarafı izleme eklemek için _Layout.cshtml dosyasını açın ve istemci tarafı JavaScript SDK yapılandırması hakkındaki makaledeki JavaScript (Web) SDK Yükleyicisi Betik tabanlı kurulum yönergelerini izleyin.

Sık sorulan sorular

Bu bölüm, sık sorulan soruların yanıtlarını sağlar.

SDK'yi nasıl kaldırabilirim?

Uygulama Analizler kaldırmak için uygulamanızdaki API'den NuGet paketlerini ve başvurularını kaldırmanız gerekir. Visual Studio'daki NuGet Paket Yöneticisi kullanarak NuGet paketlerini kaldırabilirsiniz.

  1. İzleme koleksiyonu etkinse, önce Microsoft.Application Analizler öğesini kaldırın. NuGet Paket Yöneticisi kullanarak TraceListener paketi, ancak bağımlılıkları kaldırmaz.
  2. Microsoft.Application Analizler'yi kaldırın. NuGet Paket Yöneticisi ve NuGet Paket Yöneticisi Seçenekleri denetimindeki Kaldırma seçeneklerini kullanarak web paketi ve bağımlılıklarını kaldırın.
  3. Uygulama Analizler tamamen kaldırmak için, eklenen kodu veya dosyaları ve projenize eklediğiniz API çağrılarını denetleyin ve el ile silin. Daha fazla bilgi için bkz. Uygulama Analizler SDK'sını eklediğinizde ne oluşturulur?.

Uygulama Analizler SDK'sını eklediğinizde ne oluşturulur?

Uygulama Analizler projenize eklediğinizde dosyalar oluşturulur ve bazı dosyalarınıza kod eklenir. NuGet Paketlerinin yalnızca kaldırılması her zaman dosyaları ve kodu atmaz. Uygulama Analizler tamamen kaldırmak için, eklenen kodu veya dosyaları ve projenize eklediğiniz API çağrılarını el ile denetlemeniz ve silmeniz gerekir.

Visual Studio ASP.NET projesine Uygulama Analizler Telemetrisi eklediğinizde, aşağıdaki dosyaları ekler:

  • ApplicationInsights.config
  • AiHandleErrorAttribute.cs

Aşağıdaki kod parçaları eklenir:

  • [Projenizin adı].csproj

     <ApplicationInsightsResourceId>/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/Default-ApplicationInsights-EastUS/providers/microsoft.insights/components/WebApplication4</ApplicationInsightsResourceId>
    
  • Packages.config

    <packages>
    ...
    
      <package id="Microsoft.ApplicationInsights" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.Web" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.12.0" targetFramework="net472" />
      <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.12.0" targetFramework="net472" />
    
      <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.7" targetFramework="net472" />
    
      <package id="System.Buffers" version="4.4.0" targetFramework="net472" />
      <package id="System.Diagnostics.DiagnosticSource" version="4.6.0" targetFramework="net472" />
      <package id="System.Memory" version="4.5.3" targetFramework="net472" />
      <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
      <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.2" targetFramework="net472" />
    ...
    </packages>
    
  • Layout.cshtml

    Projenizde Layout.cshtml dosyası varsa aşağıdaki kod eklenir.

    <head>
    ...
        <script type = 'text/javascript' >
            var appInsights=window.appInsights||function(config)
            {
                function r(config){ t[config] = function(){ var i = arguments; t.queue.push(function(){ t[config].apply(t, i)})} }
                var t = { config:config},u=document,e=window,o='script',s=u.createElement(o),i,f;for(s.src=config.url||'//az416426.vo.msecnd.net/scripts/a/ai.0.js',u.getElementsByTagName(o)[0].parentNode.appendChild(s),t.cookie=u.cookie,t.queue=[],i=['Event','Exception','Metric','PageView','Trace','Ajax'];i.length;)r('track'+i.pop());return r('setAuthenticatedUserContext'),r('clearAuthenticatedUserContext'),config.disableExceptionTracking||(i='onerror',r('_'+i),f=e[i],e[i]=function(config, r, u, e, o) { var s = f && f(config, r, u, e, o); return s !== !0 && t['_' + i](config, r, u, e, o),s}),t
            }({
                instrumentationKey:'00000000-0000-0000-0000-000000000000'
            });
    
            window.appInsights=appInsights;
            appInsights.trackPageView();
        </script>
    ...
    </head>
    
  • BağlanedService.json

    {
      "ProviderId": "Microsoft.ApplicationInsights.ConnectedService.ConnectedServiceProvider",
      "Version": "16.0.0.0",
      "GettingStartedDocument": {
        "Uri": "https://go.microsoft.com/fwlink/?LinkID=613413"
      }
    }
    
  • FilterConfig.cs

            public static void RegisterGlobalFilters(GlobalFilterCollection filters)
            {
                filters.Add(new ErrorHandler.AiHandleErrorAttribute());// This line was added
            }
    

Sorun giderme

Ayrılmış sorun giderme makalesine bakın.

Visual Studio 2019'un geçerli sürümünde bilinen bir sorun var: .NET Framework tabanlı uygulamalar için izleme anahtarının veya bağlantı dizesi bir kullanıcı gizli dizisinde depolanması bozuk. Anahtarın bu hataya geçici bir çözüm olarak applicationinsights.config dosyasına sabit kodlanması gerekir. Bu makale, kullanıcı gizli dizilerini kullanmayarak bu sorunu tamamen önlemek için tasarlanmıştır.

Uygulama konağınızla alma hizmeti arasındaki bağlantıyı test etme

Uygulama Analizler SDK'ları ve aracıları, alma uç noktalarımıza REST çağrıları olarak alınabilmek için telemetri gönderir. PowerShell veya curl komutlarından ham REST istemcilerini kullanarak web sunucunuzdan veya uygulama konak makinenizden alma hizmeti uç noktalarına bağlantıyı test edebilirsiniz. Bkz. Azure İzleyici Uygulama Analizler eksik uygulama telemetri sorunlarını giderme.

Açık kaynak SDK

Kodu okuyun ve koda katkıda bulunun.

En son güncelleştirmeler ve hata düzeltmeleri için sürüm notlarını inceleyin.

Release Notes (Sürüm Notları)

Sürüm 2.12 ve daha yeni sürümler için: .NET SDK'ları (ASP.NET, ASP.NET Core ve Günlük Bağdaştırıcıları dahil)

Hizmet Güncelleştirmeler ayrıca önemli Uygulama Analizler iyileştirmelerini özetler.

Sonraki adımlar