I want to log SerialPort data gracefully. Here is the detail,
To logging the input/output data, have I write a proxy class and replace all REAL SerialPort with the class? Then I can insert any logging code in the proxy class and forward Write(), Read(), and all other calls to the underlying SerialPort?
Oh, we can subclass the SerialPort.... However, we still have to create the proxy class and replace the real SerialPort with it EVERYWHERE. (Whenever the code needs SerialPort, we give it SerialPortWithLogging.) I do not think this method is clean.
I also ‘superclass’ the SerialPort. By introducing a new interface and using only the interface to contact with SerialPort, I can ensure all I/O data are logged. In the concrete implement, I forward the interface call to the SerialPort. I
think it mess my code too.
I want to log the I/O data silently in background and withdraw the logging quietly whenever possible.
I think such I/O logging requirement is so common and it must have a more graceful way to accomplish it. (Inject? Attribue?...)
Any suggestion? Thank you very much!
View Complete Post