Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make DefaultSerializerSettings non-readonly #106

Open
antgraf opened this issue Oct 11, 2023 · 4 comments
Open

Make DefaultSerializerSettings non-readonly #106

antgraf opened this issue Oct 11, 2023 · 4 comments

Comments

@antgraf
Copy link

antgraf commented Oct 11, 2023

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.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.

@whir1
Copy link
Contributor

whir1 commented Oct 16, 2023

@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
            });

@antgraf
Copy link
Author

antgraf commented Oct 17, 2023

@whir1 Is it possible with configuration file?

@whir1
Copy link
Contributor

whir1 commented Oct 17, 2023

no it's not possible with config files. But i think you can use combination with configuration and startup code to make SinkOptions

@antgraf
Copy link
Author

antgraf commented Oct 18, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants