Error while writing to event log, prevents windows service from starting?

后端 未结 2 452
孤街浪徒
孤街浪徒 2021-01-11 15:28

I am using the following code to create a custom event log in my windows service application:

public ServiceConstructor()
{         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-11 16:20

    If the source already exists it looks like you don't initialize eventLog1.Source.

    Suggest you move the initialization code to OnStart and out of the constructor.

    And move these two lines out of the if statement:

    eventLog1.Source = "WinService";
    eventLog1.Log = "WinServiceLog";
    

提交回复
热议问题