Skip to content

Improve DI friendliness of Logging #4014

@dpk83

Description

@dpk83

Feature Request

Is your feature request related to a problem?

  • Today Logging extensions provide AddOpenTelemetry extension on ILoggingBuilder, however AddProcessor and SetResourceProvider extensions are exposed on OpenTelemetryLoggerOptions. This is restrictive for services which are primarily using DI. Exposing these extensions on OpenTelemetryLoggerOptions and not on ILoggingBuilder and/or IServiceCollection limits the ability for third party libraries to provide easier capabilities for adding processor for example, or to compose the resource provider from resources exposed by multiple third party libraries etc. With the DI based mechanism a processor can then be added which can get access to other objects via DI injection and making the APIs really DI friendly for users
  • Another ask here is to also expose an override for the existing AddOpenTelemetry extension to take in options via

Describe the solution you'd like:

Expose the extensions SetResourceProvider and AddProcessor on ILoggingBuilder.

public static ILoggingBuilder AddProcessor<T>(this ILoggingBuilder builder)
            where T : BaseProcessor<LogRecord>{}

public static ILoggingBuilder SetResourceBuilder(this ILoggingBuilder loggingBuilder, ResourceBuilder resourceBuilder);

Add another overload for AddOpenTelemetry extension

public static ILoggingBuilder AddOpenTelemetry(this ILoggingBuilder builder, IConfigurationSection configurationSection) {}

Describe alternatives you've considered.

Currently we had to implement custom LoggerProvider to get the right functionality

Additional Context

We would like to move to directly using OpenTelemetryLogger and extending it as opposed to having our own implementation of LoggerProvider and Logger.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestlogsLogging signal related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions