Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/redis/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 是否有方法将额外数据传递给MyApplication\u UnhandledException事件处理程序?_Vb.net_Design Patterns_.net 3.5 - Fatal编程技术网

Vb.net 是否有方法将额外数据传递给MyApplication\u UnhandledException事件处理程序?

Vb.net 是否有方法将额外数据传递给MyApplication\u UnhandledException事件处理程序?,vb.net,design-patterns,.net-3.5,Vb.net,Design Patterns,.net 3.5,我正在为非开发人员创建一个设计模式,并将一个“捕获所有”错误处理程序与UnhandledException事件合并在一起。我想将错误写入日志文件,但日志文件名中有时间戳,因此每次运行时它都会更改。我的处理程序是否有办法接收或访问日志文件名字符串 感谢您的帮助通常未处理的异常事件处理程序位于包含启动代码的类中。因此,没有什么可以阻止您在这个类中定义一个包含日志文件名的共享公共变量。您可以在启动时从配置文件读取其值。然后在事件内部可以使用该变量打开日志文件并写入信息 编辑:在您的场景中,您可以尝试此

我正在为非开发人员创建一个设计模式,并将一个“捕获所有”错误处理程序与UnhandledException事件合并在一起。我想将错误写入日志文件,但日志文件名中有时间戳,因此每次运行时它都会更改。我的处理程序是否有办法接收或访问日志文件名字符串


感谢您的帮助

通常未处理的异常事件处理程序位于包含启动代码的类中。因此,没有什么可以阻止您在这个类中定义一个包含日志文件名的共享公共变量。您可以在启动时从配置文件读取其值。然后在事件内部可以使用该变量打开日志文件并写入信息

编辑:在您的场景中,您可以尝试此伪代码

Partial Friend Class MyApplication

    ' the name for the log file
    Public logName As String

    Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
        Dim ex As Exception = e.Exception
        If Not ex Is Nothing Then
            MessageBox.Show(ex.Message)
            Using sw = new StreamWriter(My.MyApplication.logName)
               .....
            End Using
        End If
    End Sub
End Class
在初始表单中,添加此调用以定义日志名

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    My.Application.logName = "C:\temp\text.txt"
    ' as test
    Throw New Exception("This is an unhandled exception")
End Sub
    End Sub

visual studio 08希望您将其放在此处名称空间My Partial Friend类MyApplication Private Sub MyApplication_UnhandledException(ByVal发件人作为对象,Val e作为Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs)_u处理Me.UnhandledException结束子结束类结束命名空间