Closed KostiaChorny closed 2 years ago
Hey,
when I try to add JSON file logger for my custom logger provider, it doesn't take into account optionsName when call Configure:
var textBuilder = new JsonFileLogEntryTextBuilder(new JsonWriterOptions { Indented = false }); loggingBuilder.AddJsonFile<ErrorFileLoggerProvider>(textBuilder: textBuilder, configure: options => { options.RootPath = AppContext.BaseDirectory; });
AddJsonFile() calls JsonFileLoggerExtensions.ConfigureTextBuilder() under the hood and there optionsName is not passed to Configure method
builder.Services.Configure(delegate (FileLoggerOptions options) { options.TextBuilder = textBuilder; });
so it configures default options but not the specific for the provider. The same issue with AddJsonFile method itself
public static ILoggingBuilder AddJsonFile<TProvider>(this ILoggingBuilder builder, FileLoggerContext context = null, JsonFileLogEntryTextBuilder textBuilder = null, Action<FileLoggerOptions> configure = null, string optionsName = null) where TProvider : FileLoggerProvider { builder.AddFile<TProvider>(context, null, optionsName).ConfigureTextBuilder(textBuilder); if (configure != null) { builder.Services.Configure(configure); } return builder; }
builder.Services.Configure(configure); configures default options but not the providers one.
builder.Services.Configure(configure);
As a workaround I've added custom provider the following way:
var textBuilder = new JsonFileLogEntryTextBuilder(new JsonWriterOptions { Indented = false }); var optionsName = typeof(ErrorFileLoggerProvider).ToString(); loggingBuilder.AddFile<ErrorFileLoggerProvider>(optionsName: optionsName); builder.Services.Configure(optionsName, (FileLoggerOptions options) => { options.TextBuilder = textBuilder; options.RootPath = AppContext.BaseDirectory; });
I would be really nice if you can fix it. Thanks for the great logger!
Hi!
Thanks for reporting and investigating this. Fixed by v3.3.1, which will be available on NuGet soon.
Thank you!
Hey,
when I try to add JSON file logger for my custom logger provider, it doesn't take into account optionsName when call Configure:
AddJsonFile() calls JsonFileLoggerExtensions.ConfigureTextBuilder() under the hood and there optionsName is not passed to Configure method
so it configures default options but not the specific for the provider. The same issue with AddJsonFile method itself
builder.Services.Configure(configure);
configures default options but not the providers one.As a workaround I've added custom provider the following way:
I would be really nice if you can fix it. Thanks for the great logger!