question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebHostService does not log service state changes

See original GitHub issue

Describe 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:closed
  • Created 4 years ago
  • Comments:11 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Tratchercommented, Aug 4, 2019

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

1reaction
analogrelaycommented, Nov 7, 2019

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/2612

Closing this in lieu of that one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ASP.NET Core (.Net 6) Web Application throws System. ...
When I attempt to run my .Net Web Application as a Windows Service, it does not start. It works if I just run...
Read more >
Don't let ASP.NET Core Console Logging Slow your App down
NET Core 2.x Console logging is very, very slow when it is set to ... NET Core default if there's no configuration at...
Read more >
Host ASP.NET Core in a Windows Service
When an event source can't be created using the application name, a warning is logged to the Application source and event logs are...
Read more >
Windows Server Services status remains as Started does ...
So I'm trying to update some monitoring software a customer is using to keep track of what their staff get up to (Big...
Read more >
Running a .NET Core Generic Host App as a Windows Service
In this post we'll explore how to take a .NET Core console application, running on the Generic Host, utilising IHostedService and deploy it ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found