以尽可能最小的努力从 StreamWriter 继承
我正在使用允许使用 StreamWriter 进行日志记录的外部库 - 现在我想根据日志记录的内容添加一些处理。由于我想避免循环遍历日志文件,因此我想编写一个继承自 StreamWriter 的类。
从 StreamWriter 继承并尽可能少地重新实现方法/构造函数的最佳方法是什么?
I am using an external library which allows logging using StreamWriter - now I want to add some handling based on the content of the logging. As I want to avoid to loop through the log file, I would like to write a class which inherits from StreamWriter.
What is the best way to inherit from StreamWriter with as few re-implementations of methods/constructors?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定你到底想做什么,但如果你只想检查流中写入的内容,你可以这样做:
I'm not sure of what you want to do exactly, but if you only want to inspect what is being written in the stream, you can do this:
确定外部库使用的构造函数并实现该构造函数(或仅实现全部),然后您只需重写外部库使用的写入方法即可。
Determine the constructor the external library use and implement that (or just implement them all) and then you just need to override the write method(s) that your external library uses.