Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should logging logic sit within a DDD solution?

I've created a custom filter for my MVC application, [LogAttribute]. Action methods are decorated with this and it has the responsibility to create a LogEntry object to pass into some type of provider - ILoggerProvider.

My question is, where should ILoggerProvider and it's implementations sit (I'll be wanting to use a DI technology on it)? Should they go in the domain model, the UI project or a separate class?

like image 496
David Neale Avatar asked Dec 04 '22 12:12

David Neale


2 Answers

Unless your software's primary function is Logging or Auditing, it should be an Infrastructure LoggingService.

And unless your logging implementation is tightly-coupled with your Domain Objects (I hope it isn't!), I would suggest a completely separate assembly.

like image 113
Vijay Patel Avatar answered Dec 20 '22 06:12

Vijay Patel


I'd generally contend that ILoggingProvider should sit within the domain model for a few reasons. From a logistics and sanity perspective, your domain classes probably need to reference the logger. From a DDD perspective, given the world of SOX and such we live in, one can argue that logging is a core domain feature for regulatory compliance.

Now, the implementations can definitely sit off in your infrastructure projects, no need to clutter the model with all that.

like image 44
Wyatt Barnett Avatar answered Dec 20 '22 07:12

Wyatt Barnett