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

ConfigurationSettings.PropertyNamingStrategy CamelCase does not work because JsonExtensions.LogPropertyName is hardcoded as pascal case #75

Open
AlexLexicon opened this issue Jan 23, 2023 · 1 comment

Comments

@AlexLexicon
Copy link

Describe the bug
The ConfigurationSettings.PropertyNamingStrategy does not work:

configuration
    .WriteTo.AzureAnalytics("...", "...", new ConfigurationSettings
    {
        LogName = "mylog",
        PropertyNamingStrategy = NamingStrategy.CamelCase
    })
    .Enrich.FromLogContext();

this is because the JsonExtensions.LogPropertyName is hard coded as a constant in pascal case:

internal static class JsonExtensions
{
    private const string LogPropertyName = "LogProperties";

    ...
}

So when the Flatten method is called:

internal static class JsonExtensions
{
    internal static JObject Flatten(this JObject jsonObject, bool flatObject = true)
    {
        ...

        var logPropToken = jsonObject.GetValue(LogPropertyName);
        jsonObject.Remove(LogPropertyName);

        jsonObject.Add(LogPropertyName, logPropToken.ToString(Newtonsoft.Json.Formatting.None, null));

        return jsonObject;
        }
}

it will throw a NullReferenceException because "logPropToken" is null since it could not find that property.
image

To Reproduce
Use the ConfigurationSettings.PropertyNamingStrategy set to camel case and make a log call.

Expected behavior
The log should be produced with camel cased properties

Screenshots
image

@AlexLexicon
Copy link
Author

PR: #76

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

1 participant