How can I get the name of my windows service at runtime?

I have a new windows service that I am doing in C # 4.0.

I am trying to remove an event registration code that I wrote some time ago that is in a separate class.

I want to set the event source to the name of the Windows service, without changing the code the next time I drop it into the service.

I am looking for something like this:

String source = Application.Name

But I cannot find what I have ever been.

Any members?

+3
source share
2 answers

If the code is in a service application, you can do

String source = this.ServiceName;
+4
source

. , ServiceName ServiceBase.

+1

Source: https://habr.com/ru/post/1790926/


All Articles