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

improvement: add support for dash symbol in property/key name #50

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/Seq.Client.Log4Net/Client/Log4Net/LoggingEventFormatter.cs
Original file line number Diff line number Diff line change
@@ -83,26 +83,20 @@ static void ToJson(LoggingEvent loggingEvent, StringWriter payload, IEnumerable<
WriteJsonProperty(property.ParameterName, stringValue, ref delim, payload);
}

WriteJsonProperty(SanitizeKey("log4net:Logger"), loggingEvent.LoggerName, ref delim, payload);
WriteJsonProperty("log4net:Logger", loggingEvent.LoggerName, ref delim, payload);

foreach (DictionaryEntry property in loggingEvent.GetProperties())
{
var sanitizedKey = SanitizeKey(property.Key.ToString());
if (seenKeys.Contains(sanitizedKey))
var key = property.Key.ToString();
if (seenKeys.Contains(key))
continue;

seenKeys.Add(sanitizedKey);
WriteJsonProperty(sanitizedKey, property.Value, ref delim, payload);
seenKeys.Add(key);
WriteJsonProperty(key, property.Value, ref delim, payload);
}
payload.Write("}");
}

static string SanitizeKey(string key)
{
return new string(key.Replace(":", "_").Where(c => c == '_' || char.IsLetterOrDigit(c)).ToArray());
}


static void WriteJsonProperty(string name, object value, ref string precedingDelimiter, TextWriter output)
{
output.Write(precedingDelimiter);