Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何使用不同类中的共享函数登录RichTextBox_Vb.net_Logging_Richtextbox - Fatal编程技术网

Vb.net 如何使用不同类中的共享函数登录RichTextBox

Vb.net 如何使用不同类中的共享函数登录RichTextBox,vb.net,logging,richtextbox,Vb.net,Logging,Richtextbox,在执行其他类中定义的函数时,向RichTextBox显示日志的最佳方式是什么 到目前为止,我已经尝试过类似的方法: Public Class NewClass Public Shared Function test(ByRef rtb As RichTextBox) rtb.AppendText("logging") ''' do something useful and time consuming rtb.Appen

在执行其他类中定义的函数时,向RichTextBox显示日志的最佳方式是什么

到目前为止,我已经尝试过类似的方法:

Public Class NewClass
    Public Shared Function test(ByRef rtb As RichTextBox)
        rtb.AppendText("logging")
        ''' do something useful and time consuming
        rtb.AppendText("logging")
        ''' do something useful and time consuming
        rtb.AppendText("logging")
  
    End Function
End Class
例如,我使用
NewClass.test(RichTextBox1)
执行了这个函数

它正在工作,我立即得到日志输出

但是我在“NewClass”中有很多函数,我希望有一个中心方法来进行日志记录,并将日志写入我的RichTextBox

有这样做的最佳实践吗


非常感谢大家

我不太清楚你想做什么。有一些专门用于日志记录的第三方库,可能值得研究,而不是重新发明轮子。不过,在这个主题上,只要您有一个对RichTextBox的引用,您所做的事情就可以了。更好的选择可能是将消息传递到了解RichTextBox的方法中