Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • I think your Moq code is what I want. Not sure what you mean about Law of Demeter. I guess if I didnt expose a collection the interface could have a AddToList method but not sure how you'd assert that all data has been logged Commented Mar 21, 2012 at 19:45
  • Law of Demeter is the principle of least knowledge, which can be simplified to say that you should only "talk" with your collaborators. When you have statements like a.b.c.DoX() those are Law of Demeter violations because you have to go picking through a bunch of objects you don't care about to get what you want. This makes code brittle and is best avoided. So, the idea is that as the logger, you should provide clients with what they want -- not with something they have to pick through to get what they want. Commented Mar 21, 2012 at 19:47
  • So you think exposing a ItemsRecordedCount property and n number of string properties to expose n number of previous logs would be nicer? Commented Mar 21, 2012 at 19:58
  • Well, no, I certainly wouldn't expose n named properties. What I'm talking about here is really a case by case kind of judgment call. I was just suggesting it as something to be aware of. Personally, I'd probably just not bother caching old log messages. Failing that, I'd probably expose a method like GetPreviousLogMessages(int) that returned a collection of the last n log messages. This way, you as the logger control what I get. Your way, as a client of yours, I can call logger.PreviousLogRecords.Clear() and wipe yout your 'internal' cache. Commented Mar 21, 2012 at 20:08