Setting username in application insights

拈花ヽ惹草 提交于 2019-11-30 07:09:40
Alex Bulankou

To link the user to your custom username, you can create the following telemetry initializer:

public class RealUserIDTelemetryInitializer:ITelemetryInitializer
{
    public void Initialize(Microsoft.ApplicationInsights.Channel.ITelemetry telemetry)
    {
        // Replace this with your custom logic
        if (DateTime.Now.Ticks % 2 > 0)
        {
            telemetry.Context.User.Id = "Ron Weasley";
        }
        else
        {
            telemetry.Context.User.Id = "Hermione Granger";
        }
    }
}

Then register this telemetry initializer in AI.config.

      <TelemetryInitializers>
 ....
        <Add Type="MyApp.RealUserIDTelemetryInitializer, MyApp" />
      </TelemetryInitializers>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!