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

后端 未结 2 443
孤街浪徒
孤街浪徒 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:08

    Try the following:

    EventLog.CreateEventSource("WinService", "Application");
    and eventLog1.Log = "Application";

    Also put the following in OnStart:

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

    0 讨论(0)
  • 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";
    
    0 讨论(0)
提交回复
热议问题