针对服务器端blazor的Azure应用程序洞察?

针对服务器端blazor的Azure应用程序洞察?,blazor,azure-application-insights,blazor-server-side,Blazor,Azure Application Insights,Blazor Server Side,我有一个服务器端blazor应用程序,我想使用azure application insights进行监控。目前,我只看到在启动和关闭应用程序时发送的请求,其间没有任何内容。。。我找不到任何支持Blazor的microsoft文档 是否有可能让Azure应用程序洞察与服务器端Blazor充分合作?如果是这样的话,有人知道这方面的指南吗?Blazor服务器应用程序本质上是一个asp.net核心应用程序。因此,您应该按照以下步骤设置app insights集成 在项目中添加“Microsoft.Ap

我有一个服务器端blazor应用程序,我想使用azure application insights进行监控。目前,我只看到在启动和关闭应用程序时发送的请求,其间没有任何内容。。。我找不到任何支持Blazor的microsoft文档


是否有可能让Azure应用程序洞察与服务器端Blazor充分合作?如果是这样的话,有人知道这方面的指南吗?

Blazor服务器应用程序本质上是一个asp.net核心应用程序。因此,您应该按照以下步骤设置app insights集成

  • 在项目中添加“Microsoft.ApplicationInsights.AspNetCore”nuget
  • 在appsettins.json中添加插入键

  • 注意:目前不支持客户端日志记录。不过,您可以使用community project,您有两种方法可以做到这一点——如果您计划迁移到WASM版本,基于JavaScript的方法是理想的,因为它只需要很少的更改就可以转换,但是为了解决@liero的问题,我在底部还包括了一种服务器端方法

    基于JavaScript的方法(Blazor WASM或服务器端) 我们在Blazor服务器端使用社区提供的包来满足这一需求。是的,Blazor的比赛说明是M,但我很乐意为您翻译(它在服务器端也同样有效)。请注意,根据Blazor服务器端模板中使用的路径为文件提供路径

    此外,我还创建了一个Git回购,其中包含一个项目,该项目实现了以下步骤供您审阅。您仍然需要按照步骤4中的指定设置Application Insights instrumentation键,以使其正常工作

  • 将NuGet软件包
    BlazorApplicationInsights
    安装到Blazor服务器端项目中

  • Startup.cs
    中的
    ConfigureServices()
    方法中,添加以下行:

  • services.AddBlazorApplicationInsights();
    
    您可能希望扩充设置以反映自定义角色和实例值。您可以使用以下方法来处理此问题(相同的位置):

    services.AddBlazorApplicationInsights(异步appInsights=>{
    var遥测项目=新遥测项目
    {
    标签=新字典
    {
    {“ai.cloud.role”,“SPA”},
    {“ai.cloud.roleInstance”,“Blazor服务器端”}
    }
    };
    等待appInsights.AddTelemetryInitializer(telemetryItem);
    });
    
  • 将以下@using语句添加到
    \u Imports.razor
  • @使用BlazorApplicationInsights
    
  • 将对Application Insights JS文件的引用添加到
    Pages/\u Host.cshtml
    文件的头部。从中提取脚本。请注意最后一行,您需要用Application Insights instrumentation键替换字符串值
  • 
    !函数(T,l,y){var S=T.location,k=“script”,D=“instrumentationKey”,C=“ingestionendpoint”,I=“disableExceptionTracking”,E=“ai.device”,b=“toLowerCase”,w=“crossOrigin”,N=“POST”,E=“appInsightsSDK”,T=y.name | | appInsights”;(y.name | | T[E])&(T[E]=T);var N=T[T]|函数(D){var=g=1,f=1,m={initialize:!0,queue:[],sv:“5”,version:2,config:d};函数v(e,t){var n={},a=“Browser”;返回n[e+“id”]=a[b](),n[e+“type”]=a,n[“ai.operation.name”]=S&&S.pathname | | |“"未知u”,n[“ai.internal.sdkVersion”]=“javascript:snippet|+(m.sv m.version),{time:function=new Date{var t=”“+e;return 1==t.length&&(t=“0”+t),t}return e.getUTCFullYear()+“-”+t(1+e.getUTCMonth())+“-”+t(e.getUTCDate())+“t”+t(e.getUTCMinutes())+“:”+t(e.getUTCSeconds())+“+”+((e.getUTCSeconds()))+)+”+((e.getcMilliSeconds())/1e3)。toFixed(3)+“)+”.slice(2,5)+“iKey:名称:“Microsoft.ApplicationInsights.+e.replace(/-/g,”)+“+t,采样器:100,标记:n,数据:{baseData:{ver:2}}}}}}var h=d.url | | | y.src;if(h){函数a(e){var t,n,a,i,r,o,s,c,u,p,l;g=!var=!0,m.queue=[],f | |(f=!0,t=h,s=函数(){var=e=”;if=t=t=t;if=t=,a=0;a    <ItemGroup>
          <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.13.1" />
        </ItemGroup>
    
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // The following line enables Application Insights telemetry collection.
            services.AddApplicationInsightsTelemetry();
    
            // This code adds other services for your application.
            ...
        }
    
        {
          "ApplicationInsights": {
            "InstrumentationKey": "putinstrumentationkeyhere"
          },
          "Logging": {
            "LogLevel": {
              "Default": "Warning"
            }
          }
        }