serilog-sinks-graylog
serilog-sinks-graylog copied to clipboard
Make DefaultSerializerSettings non-readonly
As I understand the idea of DefaultSerializerSettings is to override JSON settings. But in the current implementation it's impossible to assign it. Changing the pre-created object is also not possible because JsonSerializerOptions uses caching and immutable state after creation (at least in .NET 7, see ConfigurationList<TItem>.IsImmutable & JsonSerializerOptions.IsImmutable). Proposal: remove "readonly" modifier, so the field could be re-assigned before a logger creation. Alternately, JsonSerializerOptions may be added as a parameter to configuration.
@antgraf you should not change DefaultSerializerSettings. I'm not sure that the configuration system will be able to correctly read the settings for JsonSerializer. If you want to change json serializer settings then you should make GraylogSinkOptions like this
var loggerConfig = new LoggerConfiguration();
loggerConfig.WriteTo.Graylog(new GraylogSinkOptions
{
ShortMessageMaxLength = 50,
MinimumLogEventLevel = LogEventLevel.Information,
Facility = "GELF",
HostnameOrAddress = "localhost",
Port = 12209,
UseGzip = false,
JsonSerializerOptions = new JsonSerializerOptions
{
WriteIndented = true,
Encoder = new JavaScriptTestEncoder()
},
TransportType = TransportType.Udp
});
@whir1 Is it possible with configuration file?
no it's not possible with config files. But i think you can use combination with configuration and startup code to make SinkOptions
@whir1 is there an example of mixing config and runtime options? I have an impression that after instantiating it with a config there is no way to apply more changes programmatically. Thanks.