saleem-mirza / serilog-sinks-azure-analytics

Serilog sink which writes to Azure analytics
Apache License 2.0
62 stars 45 forks source link

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

Open AlexLexicon opened 1 year ago

AlexLexicon commented 1 year ago

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 commented 1 year ago

PR: #76