开发者

Windows Service not trapping error from DLL

开发者 https://www.devze.com 2023-04-08 05:21 出处:网络
I have a Windows Service that runs every 10 minutes.Whenever there is an error on the DLL, the service isn\'t throwing an error.How do I make it so the error propagates back to the Windows Service and

I have a Windows Service that runs every 10 minutes. Whenever there is an error on the DLL, the service isn't throwing an error. How do I make it so the error propagates back to the Windows Service and have it gene开发者_如何学Pythonrate an Event Viewer message, or even start the polling again?

        catch (Exception ex)
        {
            var errorMessage = ex.Message;
            if (ex.InnerException != null)
                errorMessage += " " + ex.InnerException.Message;

            eventLog1.WriteEntry(errorMessage, EventLogEntryType.Error);
            new Logging().LogMessageToFile(errorMessage, true);
        }


Problem solved! Throw it again AFTER catching it.

catch (Exception ex)
    {
        var errorMessage = ex.Message;
        if (ex.InnerException != null)
            errorMessage += " " + ex.InnerException.Message;

        eventLog1.WriteEntry(errorMessage, EventLogEntryType.Error);
        new Logging().LogMessageToFile(errorMessage, true);

        throw;
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消