none
Microsoft Service Tutorial: Eventlog WriteEntry crashes service RRS feed

  • Question

  • Hello, everybody,

    I just started working on my first service app and used this tutorial for it:

    https://docs.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer

    But after I installed and started the service, it stops immediately without writing an entry in the event log.

    So I started to deal with the problem and found out that this line caused the problem:

    eventLog1.WriteEntry("In OnStart.");

    When I remove the line, the service starts and runs until I stop it again. But if I add the line again and reinstall the service, the same thing happens as before and the service stops. I already tried to start the service with a network user who has local admin rights - but unfortunately that didn't work. I also tried to start the service with Powershell(Administrator) and the command `net start SERVICENAME`, but it's always the same.

    Any ideas?

    Thursday, August 1, 2019 8:39 AM

Answers

  • Hi,

    Can you check the event log for errors and tell us more about the Exception that causes the Windows Service to crash?

    Kind regards,

    Johnny Hooyberghs

    • Marked as answer by dr34mup Thursday, August 1, 2019 10:01 AM
    Thursday, August 1, 2019 9:28 AM

All replies

  • Hi,

    Can you check the event log for errors and tell us more about the Exception that causes the Windows Service to crash?

    Kind regards,

    Johnny Hooyberghs

    • Marked as answer by dr34mup Thursday, August 1, 2019 10:01 AM
    Thursday, August 1, 2019 9:28 AM
  • Hi Johnny,

    thanks for your answer. I checked the application eventlog and found the culprit:

    Service cannot be started. System.ArgumentException: The source 'MyNewLog' is not registered in log 'Test Service'. (It is registered in log 'Application'.) "


    It seems like I did something wrong in the first try. I googled for a solution and found that

    https://stackoverflow.com/questions/19781490/event-log-write-error

    Adding the line

    System.Diagnostics.EventLog.DeleteEventSource("MyNewLog");


    after InitializeComponent(); fixed the problem. 

    Thanks for your help. :-)



    • Edited by dr34mup Thursday, August 1, 2019 10:00 AM
    Thursday, August 1, 2019 9:49 AM