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

Why AddOpentelemetry enables Microsoft logging? #5654

Open
dariogriffo opened this issue May 26, 2024 · 1 comment
Open

Why AddOpentelemetry enables Microsoft logging? #5654

dariogriffo opened this issue May 26, 2024 · 1 comment
Labels
question Further information is requested

Comments

@dariogriffo
Copy link

dariogriffo commented May 26, 2024

What is the question?

The following setup produces 2 log entries in my OTEL collector using ILogger<>
I want to use serilog as my logging provider because of the rich features it provides. But doing so and enabling OTEL seems like Microsoft logging also is enabled.
I would expect to have an option to disable dotnet built-in logging to send logs to OTEL if the provider is not set.
Am I correct?

image

Additional context

No response

@CodeBlanch
Copy link
Member

@dariogriffo

Does it work if you do this?

var logger = new LoggerConfiguration().WriteTo.OpenTelemetry().CreateLogger();

builder.Services
	.AddOpenTelemetry().UseOtlpExporter()
	.AddLogging(c => c
		.ClearProviders() // Clear built-in ILoggerProviders and the OpenTelemetry one added by UseOtlpExporter
		.AddSerilog(logger));

May be a bit easier to read this way:

var logger = new LoggerConfiguration().WriteTo.OpenTelemetry().CreateLogger();

builder.Services
	.AddOpenTelemetry().UseOtlpExporter();

builder.Logging
	.ClearProviders() // Clear built-in ILoggerProviders and the OpenTelemetry one added by UseOtlpExporter
	.AddSerilog(logger);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants