Given an object, is there any way to get notified of when that object is garbage collected?
I am playing around with having C# extension methods behave a little more like mixins (specifically in adding logging). So basically each object gets a new Logger() method which returns an ILog that is created and cached depending on the object that is the extension method's target.
Works pretty swell, the only concern is obviously after an object goes away its logger might hang around for quite some time. I could of course set up some periodic mechanism to sweep through the logger cache and clear it but I would much rather set up some a Garbage-Collection notification so I learn about when the system is no longer using my objects.
Anyone know of a way to do this?