Enhancing events with log information?

Hi all,

Im currently thinking about enhancing the events with information
that's of interest when showing the events in a console that monitors
all events. This would require including data in the domain object
that's not necessary for keeping state in the traditional way.

Example:

AGGREGATE ROOT
Project (name="My Project", but is not included in the domain object
because not required for the state)

COMMAND (for Project):
AddMember(name = "Peter Parker")

EVENT:
MemberAddedEvent(name = "Peter Parker")

Now you want to produce an informative log message from the event
("toString()" method of the event):

"Added member 'Peter Parker' to project 'My Project'"

But the name of the project is currently not part of the domain
aggregate root "Project". Is it OK to include the name of the project
in the aggregate root domain object? I'd say yes because producing a
good event message can be seen as part of the domain object's state.

What do you think?

Cheers,
Michael

Hi Michael,

extra data (non-domain info) on events is something that I had forseen as well. I had the need for it when implementing auditing. Sometimes, you might want to attach the machine ID, user ID, user IP, etc to an event, just to be able to trace it back. Inside an event, you have access to the MetaData. There, you can add as many key-value (key=String, value=Serializable) entries as you like. The idea of this information is that it is not important to the regular event handlers.

About you question of keeping state in an aggregate jsut to be able to make events more “complete”: I would say: go for it. If it helps your application, you should definitely do it. When you say “I’d say yes because producing a
good event message can be seen as part of the domain object’s state”, I 100% agree with you. The job of an aggregate is to produce events. So they better be good.

Cheers,

Allard