I'm writing a windows service and attempting to do some logging via enterprise library 4.0. Logs go to the event log and email. The event log entries get written fine but emails are only sent after I stop the service.
So I could have 30 exceptions occur, log them and no emails would be sent until I shut it down. Then a few minutes later I would get all 30 emails. Extremely frustrating.
I figured it was because calls to send the email weren't being done asynchronosly. I tested Net.Mail.SmtpClient
to Send()
and SendAsync()
. Send()
didn't work while SendAsync()
did. Of course doing this manually isn't what I'm looking for.
I tried wrapping the Logger in a method and starting a new thread for it whenever an exception occurred. That didn't work either.
Private Sub ServiceStartup()
Try
Dim foo As Integer
foo = 1 / foo
Catch ex As Exception
Dim th As New Threading.Thread(AddressOf LogWriter)
th.Start(ex)
End Try
End Sub
Private Sub LogWriter(ByVal state As Object)
Logger.Write(state)
End Sub
Probably important to stress again, this only happens in a Windows Service. We've been using EntLib in many ASP.NET and WinForm projects and never encountered this issue.
Any ideas?