Some changes are needed to support 3.0.0. First, initializing with a TelemetryConfiguration gets an error that get_Active is not found, due to this line:
var client = new TelemetryClient(telemetryConfiguration ?? TelemetryConfiguration.Active);
Even though the TelemetryConfiguration is coming in as not null, this still gets the error. I suggest putting in a guard that requires a not null TelemetryConfiguration instead of the coalesce. Other overloads that use .Active will need to be addressed too.
To work around this I tried to initialize with my own TelemetryClient, and also tried initializing with just a ConnectionString. In both cases no error is thrown, however no logs show up in ApplicationInsights. I don't know why.
Below is my builder setup. Other things to note that are an issue but I think most likely with the Microsoft library are:
If i try to get the TelemetryClient through dependency injection, it does into an infinite loop.
If I try to create a new TelemetryClient using the TelemetryConfuration from dependency injection, then I get a null reference exception - as you can see, I had to create a new TelemetryConfiguration.
If there is another option I am missing to get this working with the new App Insights library, please advise.
Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(delegate (IWebHostBuilder webBuilder)
{
webBuilder.UseStartup<Startup>();
webBuilder.UseIISIntegration();
webBuilder.ConfigureKestrel(delegate (KestrelServerOptions options)
{
options.Limits.MinRequestBodyDataRate = null;
options.Limits.MinResponseDataRate = null;
options.Limits.KeepAliveTimeout = TimeSpan.FromMinutes(20);
});
}).UseSerilog((hostingContext, services, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration)
.Enrich.With(new UserEnricher())
.Enrich.With(new IPAddressEnricher());
var connectionString = services.GetRequiredService<TelemetryConfiguration>().ConnectionString;
loggerConfiguration.WriteTo.ApplicationInsights(
new TelemetryClient(
new TelemetryConfiguration
{
ConnectionString = connectionString
}),
TelemetryConverter.Traces);
}).Build().Run();
Some changes are needed to support 3.0.0. First, initializing with a TelemetryConfiguration gets an error that get_Active is not found, due to this line:
var client = new TelemetryClient(telemetryConfiguration ?? TelemetryConfiguration.Active);
Even though the TelemetryConfiguration is coming in as not null, this still gets the error. I suggest putting in a guard that requires a not null TelemetryConfiguration instead of the coalesce. Other overloads that use .Active will need to be addressed too.
To work around this I tried to initialize with my own TelemetryClient, and also tried initializing with just a ConnectionString. In both cases no error is thrown, however no logs show up in ApplicationInsights. I don't know why.
Below is my builder setup. Other things to note that are an issue but I think most likely with the Microsoft library are:
If i try to get the TelemetryClient through dependency injection, it does into an infinite loop.
If I try to create a new TelemetryClient using the TelemetryConfuration from dependency injection, then I get a null reference exception - as you can see, I had to create a new TelemetryConfiguration.
If there is another option I am missing to get this working with the new App Insights library, please advise.