排查无数据问题 - 用于 .NET/.NET Core 的 Application InsightsTroubleshooting no data - Application Insights for .NET/.NET Core

缺少一些遥测数据Some of my telemetry is missing

在 Application Insights 中,我只看到应用生成的一部分事件。In Application Insights, I only see a fraction of the events that are being generated by my app.

  • 如果持续看到同一个部分,可能是由于自适应采样所导致。If you are consistently seeing the same fraction, it's probably due to adaptive sampling. 要确认这一点,请打开“搜索”(通过“概述”边栏选项卡),并查看请求或其他事件的实例。To confirm this, open Search (from the overview blade) and look at an instance of a Request or other event. 单击“属性”部分底部的“...”,获取完整的属性详细信息。At the bottom of the properties section click "..." to get full property details. 如果请求计数 > 1,则表示采样正在进行。If Request Count > 1, then sampling is in operation.
  • 否则,有可能是已达到定价计划的数据率限制Otherwise, it's possible that you're hitting a data rate limit for your pricing plan. 系统每隔一分钟应用这些限制。These limits are applied per minute.

我不时地遇到数据丢失问题。I'm experiencing data loss randomly.

当应用即将停止时,控制台应用或 Web 应用中出现了数据丢失问题。I'm experiencing data loss in Console App or on Web App when app is about to stop.

  • SDK 通道在缓冲区中保留遥测数据,并分批发送这些数据。SDK channel keeps telemetry in buffer, and sends them in batches. 如果应用程序正在关闭,则你可能需要显式调用 Flush()If the application is shutting down, you may need to explicitly call Flush(). Flush() 的行为取决于使用的实际通道Behavior of Flush() depends on the actual channel used.

服务器未提供数据No data from my server

我已在 Web 服务器上安装应用,但未看到服务器提供任何遥测数据。服务器在开发计算机上正常运行。I installed my app on my web server, and now I don't see any telemetry from it. It worked OK on my dev machine.

  • 可能是防火墙有问题。Probably a firewall issue. 为 Application Insights 设置防火墙例外即可发送数据。Set firewall exceptions for Application Insights to send data.
  • IIS 服务器可能缺少某些必备组件:.NET Extensibility 4.5 和 ASP.NET 4.5。IIS Server might be missing some prerequisites: .NET Extensibility 4.5, and ASP.NET 4.5.

我已在 Web 服务器上 安装状态监视器来监视现有应用,但未看到任何结果。I installed Status Monitor on my web server to monitor existing apps. I don't see any results.


新的 Azure 区域要求使用连接字符串而不是检测密钥。New Azure regions require the use of connection strings instead of instrumentation keys. 连接字符串用于标识要与遥测数据关联的资源。Connection string identifies the resource that you want to associate your telemetry data with. 它还允许你修改可供你的资源将其用作遥测目标的终结点。It also allows you to modify the endpoints your resource will use as a destination for your telemetry. 你需要复制连接字符串,并将其添加到应用程序的代码或环境变量中。You will need to copy the connection string and add it to your application's code or to an environment variable.

FileNotFoundException:无法加载文件或程序集“Microsoft.AspNet TelemetryCorrelation”FileNotFoundException: Could not load file or assembly 'Microsoft.AspNet TelemetryCorrelation

有关此错误的详细信息,请参阅 [GitHub 问题 1610] (https://github.com/microsoft/ApplicationInsights-dotnet/issues/1610) )。For more information on this error see [GitHub issue 1610 ] (https://github.com/microsoft/ApplicationInsights-dotnet/issues/1610).

从 (2.4) 之前的 SDK 升级时,需要确保将以下更改应用到 web.configApplicationInsights.configWhen upgrading from SDKs older than (2.4) you need to make sure the following changes applied to web.config and ApplicationInsights.config:

  1. 两个 http 模块,而不是一个。Two http modules instead of one. web.config 中,应该有两个 http 模块。In web.config you should have two http modules. 对于某些场景,顺序很重要:Order is important for some scenarios:

          <add name="TelemetryCorrelationHttpModule" type="Microsoft.AspNet.TelemetryCorrelation.TelemetryCorrelationHttpModule, Microsoft.AspNet.TelemetryCorrelation" preCondition="integratedMode,managedHandler" />
          <add name="ApplicationInsightsHttpModule" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler" />
  2. ApplicationInsights.config 中,除了 RequestTrackingTelemetryModule 之外,还应具有以下遥测模块:In ApplicationInsights.config in addition to RequestTrackingTelemetryModule you should have the following telemetry module:

      <Add Type="Microsoft.ApplicationInsights.Web.AspNetDiagnosticTelemetryModule, Microsoft.AI.Web"/>

如果未能正确升级,可能会导致意外异常或无法收集遥测数据*。*Failure to upgrade properly may lead to unexpected exceptions or telemetry not being collected. _

Visual Studio 中没有“添加 Application Insights”选项No 'Add Application Insights' option in Visual Studio

在解决方案资源管理器中右键单击现有项目时,未看到任何 Application Insights 选项。_When I right-click an existing project in Solution Explorer, I don't see any Application Insights options.*

  • 工具并非支持所有类型的 .NET 项目。Not all types of .NET project are supported by the tools. 支持 Web 和 WCF 项目。Web and WCF projects are supported. 对于其他项目类型,例如桌面或服务应用程序,仍可以手动将 Application Insights SDK 添加到项目For other project types such as desktop or service applications, you can still add an Application Insights SDK to your project manually.
  • 请务必使用 Visual Studio 2013 Update 3 或更高版本Make sure you have Visual Studio 2013 Update 3 or later. 该软件预装了开发人员分析工具,其中提供了 Application Insights SDK。It comes pre-installed with Developer Analytics tools, which provide the Application Insights SDK.
  • 选择“工具”、“扩展和更新”,检查“开发人员分析工具”是否已安装并启用。 Select Tools, Extensions and Updates and check that Developer Analytics Tools is installed and enabled. 如果是,请单击“更新”查看是否有可用的更新。If so, click Updates to see if there's an update available.
  • 打开“新建项目”对话框,选择“ASP.NET Web 应用程序”。Open the New Project dialog and choose ASP.NET Web application. 如果看到了 Application Insights 选项,则表示工具已安装。If you see the Application Insights option there, then the tools are installed. 如果未看到,请尝试卸载并重新安装 Developer Analytics Tools。If not, try uninstalling and then re-installing the Developer Analytics Tools.

添加 Application Insights 失败Adding Application Insights failed

尝试将 Application Insights 添加到现有项目时看到错误消息。When I try to add Application Insights to an existing project, I see an error message.

可能的原因:Likely causes:


  • 检查是否为适当的 Azure 帐户提供了登录凭据。Check that you provided sign-in credentials for the right Azure account.
  • 在浏览器中,检查是否可以访问 Azure 门户In your browser, check that you have access to the Azure portal. 打开“设置”并查看是否有任何限制。Open Settings and see if there is any restriction.
  • 将 Application Insights 添加到现有项目:在解决方案资源管理器中,右键单击项目并选择“添加 Application Insights”。Add Application Insights to your existing project: In Solution Explorer, right click your project and choose "Add Application Insights."

遇到错误“检测密钥不能为空”I get an error "Instrumentation key cannot be empty"

可能是在安装 Application Insights 或日志记录适配器时发生了问题。Looks like something went wrong while you were installing Application Insights or maybe a logging adapter.

在解决方案资源管理器中右键单击项目,并选择“Application Insights”>“配置 Application Insights”。In Solution Explorer, right-click your project and choose Application Insights > Configure Application Insights. 将得到一个对话框,邀请你登录 Azure 并创建 Application Insights 资源或重复使用现有资源。You'll get a dialog that invites you to sign in to Azure and either create an Application Insights resource, or re-use an existing one.

生成服务器上出现“缺少 NuGet 包”"NuGet package(s) are missing" on my build server

在开发计算机上调试时所有生成都没有问题,但生成服务器上出现 NuGet 错误。Everything builds OK when I'm debugging on my development machine, but I get a NuGet error on the build server.

请参阅 NuGet Package Restore(NuGet 包还原)和 Automatic Package Restore(自动包还原)。Please see NuGet Package Restore and Automatic Package Restore.

缺少用于通过 Visual Studio 打开 Application Insights 的菜单命令Missing menu command to open Application Insights from Visual Studio

在解决方案资源管理器中右键单击我的项目时,未看到任何 Application Insights 命令,或者未看到“打开 Application Insights”命令。When I right-click my project Solution Explorer, I don't see any Application Insights commands, or I don't see an Open Application Insights command.

可能的原因:Likely causes:

  • Application Insights 资源是手动创建的,或者项目是 Application Insights 工具不支持的类型。If you created the Application Insights resource manually, or if the project is of a type that isn't supported by the Application Insights tools.
  • 开发人员分析工具已在 Visual Studio 中禁用。The Developer Analytics tools are disabled in your Visual Studio.
  • Visual Studio 版本低于 2013 Update 3。Your Visual Studio is older than 2013 Update 3.


  • 确保 Visual Studio 版本为 2013 Update 3 或更高。Make sure your Visual Studio version is 2013 update 3 or later.
  • 选择“工具”、“扩展和更新”,检查“开发人员分析工具”是否已安装并启用。 Select Tools, Extensions and Updates and check that Developer Analytics tools is installed and enabled. 如果是,请单击“更新”查看是否有可用的更新。If so, click Updates to see if there's an update available.
  • 在解决方案资源管理器中右键单击项目。Right-click your project in Solution Explorer. 如果看到命令“Application Insights”>“配置 Application Insights”,请使用它将项目连接到 Application Insights 服务中的资源。If you see the command Application Insights > Configure Application Insights, use it to connect your project to the resource in the Application Insights service.

否则,Developer Analytics Tools 不会直接支持你的项目类型。Otherwise, your project type isn't directly supported by the Developer Analytics tools. 要查看遥测数据,请登录到 Azure 门户,在左侧导航栏中选择“Application Insights”,然后选择应用程序。To see your telemetry, sign in to the Azure portal, choose Application Insights on the left navigation bar, and select your application.

从 Visual Studio 打开 Application Insights 时出现“拒绝访问”'Access denied' on opening Application Insights from Visual Studio

使用“打开 Application Insights”菜单命令时转到了 Azure 门户,但同时出现“拒绝访问”错误。The 'Open Application Insights' menu command takes me to the Azure portal, but I get an 'access denied' error.

上一次在默认浏览器中使用的 Microsoft 登录名无权访问将 Application Insights 添加到此应用时所创建的资源The Microsoft sign-in that you last used on your default browser doesn't have access to the resource that was created when Application Insights was added to this app. 有两个可能的原因:There are two likely reasons:

  • 有多个的 Microsoft 帐户 - 也许同时拥有工作帐户和个人 Microsoft 帐户。You have more than one Microsoft account - maybe a work and a personal Microsoft account? 上一次在默认浏览器中使用的登录名的关联帐户不是有权将 Application Insights 添加到项目的帐户。The sign-in that you last used on your default browser was for a different account than the one that has access to add Application Insights to the project.
    • 解决方法:单击浏览器窗口右上角的用户名并注销。使用拥有访问权限的帐户登录。Fix: Click your name at top right of the browser window, and sign out. Then sign in with the account that has access. 然后,在左侧导航栏中单击“Application Insights”并选择应用。Then on the left navigation bar, click Application Insights and select your app.
  • 其他人将 Application Insights 添加到了项目,但他们忘记向你提供创建项目的资源组的访问权限Someone else added Application Insights to the project, and they forgot to give you access to the resource group in which it was created.
    • 解决方法:如果他们使用的是组织帐户,便可以将你添加到团队;或者,他们可以单独向你授予对资源组的访问权限。Fix: If they used an organizational account, they can add you to the team; or they can grant you individual access to the resource group.

从 Visual Studio 打开 Application Insights 时出现“找不到资产”'Asset not found' on opening Application Insights from Visual Studio

使用“打开 Application Insights”菜单命令时转到了 Azure 门户,但同时出现“找不到资产”错误。The 'Open Application Insights' menu command takes me to the Azure portal, but I get an 'asset not found' error.

可能的原因:Likely causes:

  • 应用程序的 Application Insights 资源已删除;或The Application Insights resource for your application has been deleted; or
  • 检测密钥是通过直接编辑 ApplicationInsights.config 设置或更改的,但未更新项目文件。The instrumentation key was set or changed in ApplicationInsights.config by editing it directly, without updating the project file.

ApplicationInsights.config 中的检测密钥控制遥测数据发送到的位置。The instrumentation key in ApplicationInsights.config controls where the telemetry is sent. 项目文件中的某个行控制在 Visual Studio 中使用命令时打开哪个资源。A line in the project file controls which resource is opened when you use the command in Visual Studio.


  • 在解决方案资源管理器中右键单击项目,并依次选择“Application Insights”、“配置 Application Insights”。In Solution Explorer, right-click the project and choose Application Insights, Configure Application Insights. 在对话框中,可以选择将遥测数据发送到现有资源,或创建新资源。In the dialog, you can either choose to send telemetry to an existing resource, or create a new one. 或:Or:
  • 直接打开资源。Open the resource directly. 登录到 Azure 门户,在左侧导航栏中单击“Application Insights”,然后选择应用。Sign in to the Azure portal, click Application Insights on the left navigation bar, and then select your app.

在哪里可以找到我的遥测数据?Where do I find my telemetry?

我已登录到 Azure 门户,将查看 Azure 主页仪表板。但是,可以在哪里找到我的 Application Insights 数据?I signed in to the Azure portal, and I'm looking at the Azure home dashboard. So where do I find my Application Insights data?

  • 在左侧导航栏中单击“Application Insights”,并选择应用名称。On the left navigation bar, click Application Insights, then your app name. 如果未看到任何项目,则需要在 Web 项目中添加或配置 Application InsightsIf you don't have any projects there, you need to add or configure Application Insights in your web project.
    然后,会看到一些摘要图表。There you'll see some summary charts. 可以逐个单击这些图表查看详细信息。You can click through them to see more detail.
  • 在 Visual Studio 中调试应用时,请单击“Application Insights”按钮。In Visual Studio, while you're debugging your app, click the Application Insights button.

没有服务器数据(或根本没有数据)No server data (or no data at all)

我运行了应用,并在 Azure 中打开了 Application Insights 服务,但所有图表都显示“了解如何收集...”或“未配置”。I ran my app and then opened the Application Insights service in Azure, but all the charts show 'Learn how to collect...' or 'Not configured.' 或者,只有页面视图和用户数据,但没有任何服务器数据。Or, only Page View and user data, but no server data.

  • 在 Visual Studio 中以调试模式运行应用程序 (F5)。Run your application in debug mode in Visual Studio (F5). 使用应用程序,以便生成一些遥测。Use the application so as to generate some telemetry. 检查是否可以在 Visual Studio 的“输出”窗口中看到记录的事件。Check that you can see events logged in the Visual Studio output window.
    屏幕截图中显示了在 Visual Studio 中的调试模式下运行应用程序。
  • 在 Application Insights 门户中,打开诊断搜索In the Application Insights portal, open Diagnostic Search. 数据通常会先显示在此处。Data usually appears here first.
  • 单击“刷新”按钮。Click the Refresh button. 边栏选项卡会定期自行刷新,但你也可以手动刷新。The blade refreshes itself periodically, but you can also do it manually. 时间范围越大,刷新间隔就越长。The refresh interval is longer for larger time ranges.
  • 检查检测密钥是否匹配。Check the instrumentation keys match. 在 Application Insights 门户的应用主边栏选项卡中,查看“概要”下拉列表中的“检测密钥”。 On the main blade for your app in the Application Insights portal, in the Essentials drop-down, look at Instrumentation key. 然后,在 Visual Studio 的项目中,打开 ApplicationInsights.config 并找到 <instrumentationkey>Then, in your project in Visual Studio, open ApplicationInsights.config and find the <instrumentationkey>. 检查两个密钥是否相同。Check that the two keys are equal. 如果不同:If not:
    • 在门户中单击“Application Insights”,并找到具有正确密钥的应用资源;或In the portal, click Application Insights and look for the app resource with the right key; or
    • 在 Visual Studio 解决方案资源管理器中右键单击项目,并依次选择“Application Insights”、“配置”。In Visual Studio Solution Explorer, right-click the project and choose Application Insights, Configure. 重置应用,将遥测数据发送到正确的资源。Reset the app to send telemetry to the right resource.
    • 如果找不到匹配的密钥,请检查在 Visual Studio 中使用的登录凭据是否与门户中使用的相同。If you can't find the matching keys, check that you are using the same sign-in credentials in Visual Studio as in to the portal.
  • Azure 主页仪表板中,查看服务运行状况地图。In the Azure home dashboard, look at the Service Health map. 如果看到警报指示,请等待它们恢复“正常”,关闭再重新打开 Application Insights 应用程序边栏选项卡。If there are some alert indications, wait until they have returned to OK and then close and re-open your Application Insights application blade.
  • 另请查看我们的状态博客Check also our status blog.
  • 是否针对服务器端 SDK 编写了可能更改 TelemetryClient 实例或 TelemetryContext 中的检测密钥的任何代码?Did you write any code for the server-side SDK that might change the instrumentation key in TelemetryClient instances or in TelemetryContext? 或者,是否编写了可能筛选掉过多内容的筛选或采样配置Or did you write a filter or sampling configuration that might be filtering out too much?
  • 如果编辑了 ApplicationInsights.config,请仔细检查 TelemetryInitializers 和 TelemetryProcessors 的配置。If you edited ApplicationInsights.config, carefully check the configuration of TelemetryInitializers and TelemetryProcessors. 命名不当的类型或参数可能导致 SDK 不发送任何数据。An incorrectly-named type or parameter can cause the SDK to send no data.

没有有关页面视图、浏览器和使用情况的任何数据No data on Page Views, Browsers, Usage

在“服务器响应时间”和“服务器请求”图表中看到了数据,但“页面视图加载时间”或者“浏览器”或“使用情况”边栏选项卡中没有任何数据。I see data in Server Response Time and Server Requests charts, but no data in Page View Load time, or in the Browser or Usage blades.

这些数据来自网页中的脚本。The data comes from scripts in the web pages.

  • 如果将 Application Insights 添加到现有 Web 项目,则必须手动添加脚本If you added Application Insights to an existing web project, you have to add the scripts by hand.
  • 确保 Internet Explorer 不是以兼容模式显示站点。Make sure Internet Explorer isn't displaying your site in Compatibility mode.
  • 使用浏览器的调试功能(在某些浏览器中请按 F12,并选择“网络”)验证数据是否发送到了 dc.services.visualstudio.comUse the browser's debug feature (F12 on some browsers, then choose Network) to verify that data is being sent to dc.services.visualstudio.com.

没有依赖项或异常数据No dependency or exception data

请参阅依赖项遥测异常遥测See dependency telemetry and exception telemetry.

没有性能数据No performance data

性能数据(CPU、IO 速率等)适用于 Java Web 服务Windows 桌面应用IIS Web 应用和服务(如果安装了状态监视器)以及 Azure 云服务Performance data (CPU, IO rate, and so on) is available for Java web services, Windows desktop apps, IIS web apps and services if you install status monitor, and Azure Cloud Services. 可在“设置”、“服务器”下面看到这些数据。you'll find it under Settings, Servers.

将应用发布到服务器后未看到(服务器)数据No (server) data since I published the app to my server

  • 请检查是否确实将 Microsoft.Check that you actually copied all the Microsoft. ApplicationInsights DLL 连同 Microsoft.Diagnostics.Instrumentation.Extensions.Intercept.dll 一起复制到了服务器。ApplicationInsights DLLs to the server, together with Microsoft.Diagnostics.Instrumentation.Extensions.Intercept.dll
  • 在防火墙中,可能需要打开某些 TCP 端口。In your firewall, you might have to open some TCP ports.
  • 如果必须使用代理在企业网络外部发送数据,请在 Web.config 中设置 defaultProxyIf you have to use a proxy to send out of your corporate network, set defaultProxy in Web.config
  • Windows Server 2008:请确保已安装以下更新:KB2468871KB2533523KB2600217Windows Server 2008: Make sure you have installed the following updates: KB2468871, KB2533523, KB2600217.

我以前看到了数据,但现在看不到I used to see data, but it has stopped

  • 是否达到了数据点的每月配额?Have you hit your monthly quota of data points? 打开“设置/配额和定价”即可检查。如果达到了配额,可以升级计划,或付费购买更多的容量。Open the Settings/Quota and Pricing to find out. If so, you can upgrade your plan, or pay for additional capacity. 请参阅定价方案See the pricing scheme.

未按预期看到所有数据I don't see all the data I'm expecting

如果应用程序发送大量数据,并且使用的是用于 ASP.NET 的 Application Insights SDK 2.0.0-beta3 或更高版本,则自适应采样功能可以正常运行,只发送一部分遥测数据。If your application sends a lot of data and you are using the Application Insights SDK for ASP.NET version 2.0.0-beta3 or later, the adaptive sampling feature may operate and send only a percentage of your telemetry.

可以禁用该功能,但不建议这样做。You can disable it, but this is not recommended. 采样旨在正确传输相关遥测数据,以便进行诊断。Sampling is designed so that related telemetry is correctly transmitted, for diagnostic purposes.

客户端 IP 地址为 IP address is

在 2018 年 2 月 5 日,我们宣布我们删除了客户端 IP 地址的日志记录。On February 5 2018, we announced that we removed logging of the Client IP address. 这不会影响地理位置。This does not affect Geo Location.


如果需要 IP 地址的前 3 个八位字节,则可以使用遥测初始化程序添加自定义属性。If you need the first 3 octets of the IP address, you can use a telemetry initializer to add a custom attribute. 这不会影响 2018 年 2 月 5 日之前收集的数据。This does not affect data collected prior to February 5, 2018.

用户遥测数据包含错误的地理数据Wrong geographical data in user telemetry

城市、区域和国家/地区维度派生自 IP 地址,因此不一定始终都是准确的。The city, region, and country dimensions are derived from IP addresses and aren't always accurate. 首先针对位置处理这些 IP 地址,然后将其更改为 以进行存储。These IP addresses are processed for location first and then changed to to be stored.

在 Azure 云服务中运行时发生“找不到方法”异常Exception "method not found" on running in Azure Cloud Services

生成的项目是否面向 .NET 4.6?Did you build for .NET 4.6? Azure 云服务角色不能现成地支持 4.6。4.6 is not automatically supported in Azure Cloud Services roles. 请先在每个角色上安装 4.6,再运行应用。Install 4.6 on each role before running your app.

故障排除日志Troubleshooting Logs

按照这些说明来捕获框架的故障排除日志。Follow these instructions to capture troubleshooting logs for your framework.

.NET Framework.NET Framework

  1. 从 NuGet 安装 Microsoft.AspNet.ApplicationInsights.HostingStartup 包。Install the Microsoft.AspNet.ApplicationInsights.HostingStartup package from NuGet. 安装的版本必须与当前安装的 Microsoft.ApplicationInsighs 版本匹配The version you install must match the current installed version of Microsoft.ApplicationInsighs

  2. 修改 applicationinsights.config 文件以包括以下内容:Modify your applicationinsights.config file to include the following:

      <Add Type="Microsoft.ApplicationInsights.Extensibility.HostingStartup.FileDiagnosticsTelemetryModule, Microsoft.AspNet.ApplicationInsights.HostingStartup">

    应用程序必须对配置的位置具有写入权限Your application must have Write permissions to the configured location

  3. 重新启动进程,以便 SDK 获取这些新设置Restart process so that these new settings are picked up by SDK

  4. 完成后还原这些更改。Revert these changes when you are finished.

.NET Core.NET Core

  1. 安装 NuGet 中适用于 ASP.NET Core 的 Application Insights SDK NuGet 包Install the Application Insights SDK NuGet package for ASP.NET Core package from NuGet. 安装的版本必须与当前安装的 Microsoft.ApplicationInsights 版本匹配。The version you install must match the current installed version of Microsoft.ApplicationInsights.

    Microsoft.ApplicationInsights.AspNetCore 的最新版本为 2.14.0,它引用 Microsoft.ApplicationInsights 版本 2.14.0。The latest version of Microsoft.ApplicationInsights.AspNetCore is 2.14.0, and it refers to Microsoft.ApplicationInsights version 2.14.0. 因此,要安装的 Microsoft.ApplicationInsights.AspNetCore 版本应该是 2.14.0。Hence the version of Microsoft.ApplicationInsights.AspNetCore to be installed should be 2.14.0.

  2. 修改 Startup.cs 类中的 ConfigureServices 方法:Modify ConfigureServices method in your Startup.cs class.:

    services.AddSingleton<ITelemetryModule, FileDiagnosticsTelemetryModule>();
    services.ConfigureTelemetryModule<FileDiagnosticsTelemetryModule>( (module, options) => {
        module.LogFilePath = "C:\\SDKLOGS";
        module.LogFileName = "mylog.txt";
        module.Severity = "Verbose";
    } );

    应用程序必须对配置的位置具有写入权限Your application must have Write permissions to the configured location

  3. 重新启动进程,以便 SDK 获取这些新设置Restart process so that these new settings are picked up by SDK

  4. 完成后还原这些更改。Revert these changes when you are finished.

使用 PerfView 收集日志Collect logs with PerfView

PerfView 是一个免费的诊断和性能分析工具,它可以从许多源收集诊断信息并将其可视化,从而帮助你查明 CPU、内存和其他问题。PerfView is a free diagnostics and performance-analysis tool that help isolate CPU, memory, and other issues by collecting and visualizing diagnostics information from many sources.

PerfView 可以捕获 Application Insights SDK 日志和 EventSource 自我故障排除日志。The Application Insights SDK log EventSource self-troubleshooting logs that can be captured by PerfView.

若要收集日志,请下载 PerfView 并运行以下命令:To collect logs, download PerfView and run this command:

PerfView.exe collect -MaxCollectSec:300 -NoGui /onlyProviders=*Microsoft-ApplicationInsights-Core,*Microsoft-ApplicationInsights-Data,*Microsoft-ApplicationInsights-WindowsServer-TelemetryChannel,*Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Dependency,*Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Web,*Microsoft-ApplicationInsights-Extensibility-DependencyCollector,*Microsoft-ApplicationInsights-Extensibility-HostingStartup,*Microsoft-ApplicationInsights-Extensibility-PerformanceCollector,*Microsoft-ApplicationInsights-Extensibility-EventCounterCollector,*Microsoft-ApplicationInsights-Extensibility-PerformanceCollector-QuickPulse,*Microsoft-ApplicationInsights-Extensibility-Web,*Microsoft-ApplicationInsights-Extensibility-WindowsServer,*Microsoft-ApplicationInsights-WindowsServer-Core,*Microsoft-ApplicationInsights-LoggerProvider,*Microsoft-ApplicationInsights-Extensibility-EventSourceListener,*Microsoft-ApplicationInsights-AspNetCore

可根据需要修改这些参数:You can modify these parameters as needed:

  • MaxCollectSecMaxCollectSec. 设置此参数可防止 PerfView 无限期运行并影响服务器的性能。Set this parameter to prevent PerfView from running indefinitely and affecting the performance of your server.
  • OnlyProvidersOnlyProviders. 设置此参数可以仅从 SDK 收集日志。Set this parameter to only collect logs from the SDK. 可根据自己的具体调查自定义此列表。You can customize this list based on your specific investigations.
  • NoGuiNoGui. 设置此参数可以在不使用 GUI 的情况下收集日志。Set this parameter to collect logs without the GUI.

有关详细信息,请参阅:For more information,

使用 dotnet-trace 收集日志Collect logs with dotnet-trace

在基于 Linux 的环境中,收集用于故障排除的日志的另一种特别有用的方法是使用 dotnet-traceAn alternate method of collecting logs for troubleshooting that may be particularly helpful for linux-based environments is dotnet-trace

dotnet-trace collect --process-id <PID> --providers Microsoft-ApplicationInsights-Core,Microsoft-ApplicationInsights-Data,Microsoft-ApplicationInsights-WindowsServer-TelemetryChannel,Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Dependency,Microsoft-ApplicationInsights-Extensibility-AppMapCorrelation-Web,Microsoft-ApplicationInsights-Extensibility-DependencyCollector,Microsoft-ApplicationInsights-Extensibility-HostingStartup,Microsoft-ApplicationInsights-Extensibility-PerformanceCollector,Microsoft-ApplicationInsights-Extensibility-EventCounterCollector,Microsoft-ApplicationInsights-Extensibility-PerformanceCollector-QuickPulse,Microsoft-ApplicationInsights-Extensibility-Web,Microsoft-ApplicationInsights-Extensibility-WindowsServer,Microsoft-ApplicationInsights-WindowsServer-Core,Microsoft-ApplicationInsights-LoggerProvider,Microsoft-ApplicationInsights-Extensibility-EventSourceListener,Microsoft-ApplicationInsights-AspNetCore

如何删除 Application InsightsHow to remove Application Insights

按照此文中提供的步骤,了解如何在 Visual Studio 中删除 Application Insights。Learn how to remove Application Insights in Visual Studio by following the steps provide in the removal article.

仍然无法解决问题...Still not working...