sho*_*tsy 5 .net stack-overflow email
我正在开发一个.Net服务器应用程序,它应该不断运行.我希望每次服务器进程因任何原因终止时都会发送通知电子邮件.理想情况下,如果异常导致终止,则电子邮件应包含异常消息和堆栈跟踪.我知道某些例外是无法捕获的,例如StackOverflowException.那么如何记录/发送StackOverflowException服务器进程中发生的通知?
我正在考虑创建第二个进程来监视服务器进程.但是,如何获得异常的详细信息呢?
我有一个应用程序(显示的代码)可以拦截未处理的异常并显示自定义异常对话框,这可能会有一些帮助吗?
Imports BM.BEAST.Presenters
Imports BM.BEAST.Security
Imports BM.BEAST.Business
Imports System.Threading
Public Class StartUp
Shared Sub UnhandledException(ByVal sender As Object, ByVal e As System.Threading.ThreadExceptionEventArgs)
Dim unhandledException As New UnhandledExceptionView
unhandledException.uxExceptionDetails.Text = e.Exception.ToString
unhandledException.ShowDialog()
If unhandledException.uxRestart.Checked Then
Application.Restart()
Else
Application.Exit()
End If
End Sub
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Entry point
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Shared Sub Main()
'All unhandled exceptions are handled by the sub UnhandledException()
'which displays a BEAST exception dialog and gives the user the chance
'to copy the error to clipboard for pasting into email etc..
AddHandler Application.ThreadException, AddressOf UnhandledException
'Application framework not enabled
My.User.InitializeWithWindowsUser()
'Users must be authenticated
If My.User.IsAuthenticated Then
Dim securityPrincipal As Security.ISecurityPrincipal = Nothing
Dim applicationController As ApplicationController = Nothing
Try
'Custom security principal for use throughout the session
securityPrincipal = ServiceGateway.Instance.StartUserSession
AppDomain.CurrentDomain.SetThreadPrincipal(securityPrincipal)
Thread.CurrentPrincipal = securityPrincipal
applicationController = applicationController.GetInstance
applicationController.RegisterNavigator(New ApplicationNavigator)
'If a user holds more than 1 role they will have to select
'the role they want applied for use throughout the session
If securityPrincipal.Roles.Count > 1 Then applicationController.NavigateTo("SelectRoleView")
applicationController.NavigateTo("ShellView")
Catch ex As Exceptions.InvalidUserNameException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Invalid User")
Catch ex As Exceptions.UserDisabledException
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "User Disabled")
Catch ex As System.Net.Sockets.SocketException
MsgBox("The xxxxx Server is unavailable, contact the System Administrator.", MsgBoxStyle.Exclamation, "Server Unavailable")
End Try
Else
MsgBox("User not authenticated, the application will terminate.", MsgBoxStyle.Exclamation, "Authentication")
End If
My.Settings.Save()
Application.Exit()
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)