Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何为Appinsight的修改用户ID使用遥测服务?_C#_.net_Azure_Asp.net Core_Appinsights - Fatal编程技术网

C# 如何为Appinsight的修改用户ID使用遥测服务?

C# 如何为Appinsight的修改用户ID使用遥测服务?,c#,.net,azure,asp.net-core,appinsights,C#,.net,Azure,Asp.net Core,Appinsights,我在修改Appinsight请求日志中的用户ID时遇到了很大的麻烦。如果我在下面创建一个新的Appinsight环境,代码工作得很好!但若我在现有的应用程序中使用下面的代码,那个么用户ID或其他请求属性或页面视图属性就不能更改。我之前的一位开发人员使用向导创建了appinsight。我不知道为什么我不能更改userid值。如何修改它?是否存在用于更改修改appinsight上下文属性的配置文件。我的项目是Asp.NETCore2.2。我正在使用“Microsoft.ApplicationInsi

我在修改Appinsight请求日志中的用户ID时遇到了很大的麻烦。如果我在下面创建一个新的Appinsight环境,代码工作得很好!但若我在现有的应用程序中使用下面的代码,那个么用户ID或其他请求属性或页面视图属性就不能更改。我之前的一位开发人员使用向导创建了appinsight。我不知道为什么我不能更改userid值。如何修改它?是否存在用于更改修改appinsight上下文属性的配置文件。我的项目是Asp.NETCore2.2。我正在使用“Microsoft.ApplicationInsights;”作为nuget包

public class MyTelemetryInitializer : ITelemetryInitializer
{
    public MyTelemetryInitializer()
    {
    }

    public void Initialize(ITelemetry telemetry)
    {
        try
        {

                telemetry.Context.User.Id = "yusuf"; //=> NOT WORKING!!
                telemetry.Context.Cloud.RoleInstance = "test"; //=> NOT WORKING!!
                telemetry.Context.Properties["EventId"] = "deneme";

                ISupportProperties propTelemetry = (ISupportProperties)telemetry;

                if (propTelemetry.Properties.ContainsKey("EventId"))
                {
                    propTelemetry.Properties["EventId"] = "deneme2"; //=> Working!!!
                }


        }
        catch (Exception ex)
        {

            Trace.WriteLine(ex.Message);
        }
    }

}
Startup.cs:

      public void ConfigureServices(IServiceCollection services)
    {
     ......
       .......
     services.AddSingleton<ITelemetryInitializer,MyTelemetryInitializer>(); 


        services.AddSession();
        ....
        }
  public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseApplicationInsights()
            .UseStartup<Startup>()
            .Build();
}
public void配置服务(IServiceCollection服务)
{
......
.......
services.AddSingleton();
services.AddSession();
....
}
Program.cs:

      public void ConfigureServices(IServiceCollection services)
    {
     ......
       .......
     services.AddSingleton<ITelemetryInitializer,MyTelemetryInitializer>(); 


        services.AddSession();
        ....
        }
  public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseApplicationInsights()
            .UseStartup<Startup>()
            .Build();
}
公共类程序
{
公共静态void Main(字符串[]args)
{
BuildWebHost(args.Run();
}
公共静态IWebHost BuildWebHost(字符串[]args)=>
WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup()
.Build();
}
如果我查看“Application Insights Search”,我可以看到用户ID已更改:

但当我在AZURE中查找应用程序insgiht时,Userid是空的


如果(userid!=null)它是否通过
?你调试过应用程序吗?他是什么时候创建应用程序洞察的,他选择了哪种应用程序洞察?application insights创建中有一些更改,在前面的示例中,当您创建application insights时,有javascript/asp.net等的类型。@PeterBons yes。我通过了。不用担心。@loki,当您在本地运行.net core 2.2项目时,如在visual studio中,在visual studio输出窗口或application insights搜索窗口中,您能看到用户ID已更改吗?让我们来看看。