WebHostService does not log service state changes
See original GitHub issueDescribe the bug
The WebHostService (AspNetCore
) inherits from ServiceBase (corefx
) which has a public property called AutoLog
that is documented as follows: Indicates whether to report Start, Stop, Pause, and Continue commands in the event. This doesn’t seem to work for the application (netcoreapp2.2
) I am developing. I am following the guide Host ASP.NET Core in a Windows Service to accomplish this. One of my requirements is that I log state changes to the event viewer.
The documentation shows how to run as a custom service so I can handle starting and stopping events myself, but my understanding is that these event logs should already been covered by the ServiceBase using the AutoLog
property. I cannot find any logs of the service being started or stopped in the event viewer (running Windows 10).
I have managed to accomplish logging to the event viewer by using the .AddEventLog() in the ConfigureLogging on the WebHostBuilder and creating a CustomWebHostService
as documented, but should I? Is the documentation / implementation of AutoLog on the ServiceBase (or any other relevant code) bugged?
To Reproduce
Follow the guide Host ASP.NET Core in a Windows Service. Install and start the service and observe that the event viewer does not contain any start/stop/pause events on Windows 10.
Edit: I did find that Windows Server 2019 does log start/stopped events under id 7036. I guess this somehow does respect the AutoLog
property.
Edit2: Reproducible sample: https://github.com/Erikvl87/AspNetCore-issue-12352
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (1 by maintainers)
Top GitHub Comments
Note this functionality has moved to the generic IHost and any improvement should be made there instead. (And this issue should be moved to Extensions).
There were some design changes in the move and RunAsService no longer exists there. We would use the normal options pattern to provide a name. https://github.com/aspnet/Extensions/blob/master/src/Hosting/WindowsServices/src/WindowsServiceLifetimeHostBuilderExtensions.cs
Reviving this. I’ll open a more specific issue describing that proposal: Allow setting the ServiceName property in
UseWindowsService
(via Options). https://github.com/aspnet/Extensions/issues/2612Closing this in lieu of that one.