Issue with restrictedToMinimumLevel in appsetting.json
Closed this issue ยท 9 comments
I have issues using restrictedToMinimumLevel in the appsettings.json file.
It's working OK when bootstrapping in Program.cs, but not when using the json configuration.
Examples
Works fine:
Program.cs
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateBootstrapLogger();
builder.Host.UseSerilog((hostingContext, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration);
loggerConfiguration.WriteTo.OpenTelemetry((options) =>
{
options.Endpoint = "http://127.0.0.1:4317";
options.Protocol = OtlpProtocol.Grpc;
options.RestrictedToMinimumLevel = LogEventLevel.Information;
});
});
Does not work (RestrictedToMinimumLevel is ignored, and will use default minimumlevel)
Program.cs
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateBootstrapLogger();
builder.Host.UseSerilog((hostingContext, loggerConfiguration) =>
{
loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration);
});
appsettings.json
"Serilog": {
{
"Name": "OpenTelemetry",
"Args": {
"endpoint": "http://127.0.0.1:4317",
"protocol": "Grpc",
"restrictedToMinimumLevel": "Information"
}
}
]
}
Expected: All logentries are on information level
Actual: All logentries are on minimum level (in my case debug)
Thanks for the note ๐. Serilog sinks normally, by convention, include restrictedToMinimumLevel
and levelSwitch
in their configuration methods, but those args are missing from the configuration overload you're calling:
Using the same parameter names, docs, and semantics as those args on WriteTo.Console()
or any other core sink should make this a reasonably straightforward change, if someone has a chance to send a PR.
Thanks for the note ๐. Serilog sinks normally, by convention, include
restrictedToMinimumLevel
andlevelSwitch
in their configuration methods, but those args are missing from the configuration overload you're calling:Using the same parameter names, docs, and semantics as those args on
WriteTo.Console()
or any other core sink should make this a reasonably straightforward change, if someone has a chance to send a PR.
I tried to code for this issue, can those codes working correctly?
Hi and thanks for the bugfix on this.
I see that it has been merged and it would be really helpful to have a new release including this fix :)
Thank you very much for your help.
Glad that i could be of help! ๐
@CloudeaSoft there should be a -dev nuget? https://www.nuget.org/packages/Serilog.Sinks.OpenTelemetry/#versions-body-tab
(you can close this when you validate?)
Any news on the release?
Sorry, I'm not really sure about the version control of the nuget package.
I've just drafted the 2.0.0 release PR: #135
Is anyone able to confirm that the 2.0.0-dev-* packages work as expected for them? Thanks!
Released now ๐