Search code examples
c#loggingmemento

Generic field changed event


I'm currently trying to make a Logger for hundreds of classes, which listens for 3 property's change, and creates a log message if they do.

  public class MementoLoggerUtility<SLOC, AVAL, BVAL>
    {
        private SLOC Loc;
        private AVAL Val1;
        private BVAL Val2;

        /// <summary>
        /// CTOR
        /// </summary>
        public MementoLoggerUtility(ref SLOC loc, ref AVAL val1, ref BVAL val2)
        {
            Loc = loc;
            Val1 = val1;
            Val2 = val2;            
        }

I would pass the 3 property in the listened object's constructor, but I need an OnPropertyChanged event into this class to listen on their changes.

(I can't write it to the listened object's property setter.)

Is this plan even possible to implement? If not, can you propose me another option?


Solution

  • I think it is.. if your solution is intended for only test purposes I think there aren't many problems, else, you should to consider the potentially impact on application performance, mostly related to the number of objects simultaneously running and relative logging objects who are polling on them..

    you should provide one threaded polling method for each class and when the states you are polling change then raise event..