Reputation: 23789
I'm trying to figure out how to deal with logging in a CQRS setting. The situation is as follows:
Foo.Events
where events inherit from EventArgs
(not sure why) and correspondingly the broker expects all events to inherit from this class.Now, I'm trying to figure out how to fit logging in this. In CQRS, it seems to me that logging isn't an event per se, it is rather the system's response to an event. On the other hand, a log request seems like a command, i.e. the C in CQRS.
I'd love to put this into the event broker somehow, but I'm not sure. Do commands belong on the event broker anyway, can we assume that the broker is just some messaging system that doesn't really care if it's C or Q?
Your help is much appreciated!
Upvotes: 4
Views: 2295
Reputation: 51634
Logging is an infrastructural concern. Commands and events are (usually) business related. Logging just happens whenever necessary and the technical implementation is up to you. It is neither command nor event. It records that one of these has occurred. In fact you might even want to log certain queries.
You can store the events in an event log (or even in an event store) and use them as a log. You can also wrap your command and query handlers with a logging handler if you need to record commands and/or certain queries.
Upvotes: 3
Reputation: 37719
Logging manifests in different ways in different contexts. In CQRS, the storage of domain events can be regarded as an audit log. You can also have application/infrastructural logging which logs technical system events. These are typically stored in a different place and are mostly write only. On .NET, frameworks such as log4net or NLog are used to handle logging of technical system events. You can create an Rx-based implementation for these frameworks, though that might be adding needless complexity.
Also, you certainly can place log messages on a message queue, though I'm not sure what you'd get out of that. Is the event broker you have an in-process broker or distributed? If the latter, then I'd steer away from that unless absolutely necessary.
Upvotes: 2