-
Notifications
You must be signed in to change notification settings - Fork 9
Added structured logging support #184
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks like a good change, going in the right direction.
I'd also recommend adding some tests & updating the readme with your additions.
@@ -8,6 +8,10 @@ internal class GraylogMessageBuilder | |||
private const string NLogLogLevelPropertyName = "nlog_level_name"; | |||
private readonly JsonObject _graylogMessage = new JsonObject(); | |||
private static readonly DateTime _epochTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); | |||
private string _structuredLoggingParameterName; | |||
|
|||
public GraylogMessageBuilder(string structuredLoggingParameterName = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this to a builder method. and out of the ctor
Something like WithStructuredLoggingParameter(string parameterName) {...)
var kvPairs = item.Split(new char[] { '=' }, 2); | ||
if (kvPairs.Length == 2) | ||
{ | ||
WithCustomProperty(kvPairs[0].Replace(" ", string.Empty), kvPairs[1]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do any sanitization of the property name per the gelf spec?
Structured logging is already supported with the current library. Example (injected Microsoft ILogger through NLog) |
Im new at this tell me if I've done it wrong.
Have added functionality to handle structured logging, such that the parameters you log against will appear in Greylog as parameters, not just as a conglomerated field.
To use fill in the StructuredLoggingParameterName feild in the config file and assign ${all-event-properties} to a parameter with the same name.