I want to ignore the null properties in the output window while using serilog. the properties which will be null should be ignored and the rest of the properties should be logged.
Have already looked into AttributedDestructuringPolicy but of no help. Any help or lead would be appreciated.
please see the below link to get an idea about my question: https://github.com/serilog/serilog/issues/1286
I have created a custom method to arrange my log as below :-
public static Log PrepareLogDetails(
ActivityState activityState,
string compressedData,
string exceptionMessage,
string exceptionStacktrace,
string correlationId,
Initiator initiator,
string initiatorId,
Dictionary<string, string> metadata)
{
var step = new Step()
{
activityState = activityState,
CompressedData = compressedData.GZipStringCompress()
};
if (!string.IsNullOrEmpty(exceptionMessage))
{
step.Exception = new Adapter_Exception()
{
Message = exceptionMessage,
StackTrace = exceptionStacktrace
};
}
var log = new Log()
{
CorrelationId = correlationId,
Initiator = initiator,
InitiatorApp = "VPAdjustment",
InitiatorId = initiatorId,
Step =step,
Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(),
Metadata= metadata
};
return log;
}
Now when I am returning the log object, it contains the null properties as well. I want to ignore those null properties while returning the log object. Any idea how can I achieve this ?