Skip to content

Generic AddJsonFile<TProvider>(configure:) registers configure on Options.DefaultName — unfixed half of #22 #39

Description

@gerritgoetzen

The v3.3.1 fix for #22 was incomplete. #22 reported two defects in the generic AddJsonFile<TProvider>: (a) ConfigureTextBuilder ignoring optionsName, and (b) the user configure callback being registered against Options.DefaultName instead of the provider's named-options instance. The fix (commit fe6a9fe) addressed (a) only; (b) is still present in v4.1.0.

Where: source/FileLogger.Json/JsonFileLoggerExtensions.cs. Every generic overload (<TProvider>, <TProvider,TOptions>, and the bindOptions variant) calls builder.AddFile<…>(context, configure: null, optionsName) and then builder.Services.Configure(configure) — unnamed, so it binds to Options.DefaultName. The provider reads its options under optionsName ?? typeof(TProvider).ToString(), so the configure callback never reaches it. Within a single call, TextBuilder lands on the named instance while the user's configure lands on DefaultName.

Scope: this fires whenever configure is supplied — an explicit optionsName is not required, since the provider reads under typeof(TProvider).ToString(), never DefaultName.

Contrast: the sibling AddFile<TProvider> in FileLoggerFactoryExtensions.cs is correct — builder.Services.Configure(optionsName, configure).

Repro:

loggingBuilder.AddJsonFile<MyFileLoggerProvider>(
    optionsName: "MyJson",
    configure: o => o.RootPath = AppContext.BaseDirectory);

The resulting provider does not see RootPath — it reads options "MyJson", but configure was applied to "".

Suggested fix: forward configure into AddFile<TProvider>(context, configure, optionsName), which already names it, and drop the trailing unnamed Services.Configure. Equivalent: builder.Services.Configure(optionsName ?? typeof(TProvider).ToString(), configure).

Workaround (per #22): omit configure: and call Services.Configure<FileLoggerOptions>(optionsName, …) separately.

Version: 4.1.0. Related: #22 (original report, closed as fixed in v3.3.1).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions