1

I have a web project implementing Policy Based Authorization. I have two different API'es, i want one API to log to one Instance to Application Insights, and the other API to log to another instance.

I am using log4net. I tried two different appenders, and created two different ServiceLoggers for log4net, and used dependency Injection to inject the ServiceLogger to it's respectable API Controller. In every service i used the logger in this manner var specialLogger = LogManager.GetLogger("SomeApplicationInsightAppender");

I added the instrumentation keys in every appender, and in appsettings.json i could only add one instrumentation key.

When i call the api'es, the requests get logged into one instance which is the instrumentation key in the appsettings.json, however, the normal logs using the serviceslogger i created:

  • Sometimes i see the log from one API correctly in the Application Insights Instance it should log to, but not the other request in the other Application Insights Instance.
  • Sometimes it is the other way around.

Is it a limitation in the framework to log only to one Application Insights Instance per App? Any help would be appreciated.

AEH
  • 36
  • 5

1 Answers1

0

Recently, I tried this case. I created a Springboot application with 2 Api. Hope my test will help you. Here's the code:

@RestController
public class HelloWorld {

    @RequestMapping(value="/hello")
    public String greeting() {
        TelemetryConfiguration.getActive().setInstrumentationKey("4e5xxxxd36");
        TelemetryClient telemetryClient = new TelemetryClient();
        telemetryClient.trackEvent("URI /greeting is triggered");
        return "hello";
    }
    
    @RequestMapping(value="/getUserInfo")
    public String getUserInfo() {
        TelemetryConfiguration.getActive().setInstrumentationKey("dd6xxxxaba");
        TelemetryClient telemetryClient = new TelemetryClient();
        telemetryClient.trackEvent("URI /getUserInfo is triggered");
        return "{user:zhangsan;age:16}";
    }
}

As you can see, I created 2 different TelemetryClient instances. And when I reached azure portal to see these tracks, I found the result like below: enter image description here enter image description here

Tiny Wang
  • 10,423
  • 1
  • 11
  • 29