2

I am serializing events with Serilog, this events can be sent from a wide arrange of services that extend a base abstract class that contains the essential information for any event, and the child classes add all needed specific event information.

The problem is that in the log only the child class properties are being stored and the parent ones are left out. Is there a way to force serilog to include the base class properties on its serialization?

I tried changing the base class to non-abstract and also setting the Destructor.ToMaximumLength to 10000 but still no luck.

public abstract class AnalyticsEvent
{
    public readonly Guid EventId = Guid.NewGuid();
    public readonly DateTimeOffset EventTime = DateTimeOffset.UtcNow;
    public readonly EventGroups EventGroup;
    public readonly Guid? TransactionId;
    public readonly string EventName;

    public AnalyticsEvent(EventGroups eventGroup, Guid? transactionId, string eventName)
    {
        EventGroup = eventGroup;
        TransactionId = transactionId;
        EventName = eventName;
    }
}
2
  • Can you please post a snippet of the base class properties you need to include? Are they public, or protected? Thanks! Commented Jun 22, 2016 at 23:29
  • @NicholasBlumhardt I added the snippet Commented Jun 23, 2016 at 0:02

1 Answer 1

3

Serilog's destructuring only picks up properties; the members on your base class are fields. Converting them to properties should work as expected.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.