Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application insight not working when keyed services are added - No service for type TelemetryConfiguration #227

Closed
knilecrack opened this issue Sep 4, 2024 · 1 comment

Comments

@knilecrack
Copy link

knilecrack commented Sep 4, 2024

Hello,

I just wanted to post this here in case someone else runs into same issue as I did, and not lose a day or two trying to figure out what's happening. In case this should not be here feel free to close it

This is in particular bug with App insights and has nothing to do with serilog. The problem is when there are keyed services registered in DI (.net 8 feature) TelemetryConfiguration won't be registered and if you are using something like this

Log.Logger = new LoggerConfiguration()
    .WriteTo.ApplicationInsights(
        serviceProvider.GetRequiredService<TelemetryConfiguration>(),
	TelemetryConverter.Traces)
    .CreateLogger();

to configure serilog it will throw an exception
System.InvalidOperationException: 'No service for type 'Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration' has been registered.

you can find more information here

I can see that for some people workaround was to register App insight before any other services.

I've experienced this issue with following versions:
Serilog.Sinks.ApplicationInsights - 4.0.0
Serilog.AspNetCore - 8.0.2

@nblumhardt
Copy link
Contributor

Thanks @knilecrack 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants