Context
I have a .NET Core 3.1 Console Application that is being run as a Windows service. It's set up using:
Host.CreateDefaultBuilder(args)
.UseWindowsService()
And installed as a Windows service using sc.exe create.
Question
Some users want to install multiple versions of this same console application on the same machine, which works fine! However, when viewing the logs in the Event Viewer, you can't tell which Windows service each record belongs to, as they all have the same source name.
Is there a standard way to set up a source name at installation time?
Research
- The documentation indicates that
UseWindowsService
will set the "application name" as the default source name. Which is always the same name. - This issue seems to indicate that there is no way to do it through configuration.
- The following code would allow me to set it manually, but I'd like to follow an industry standard if one exists:
// Inside .ConfigureServices((hostContext, services) =>
services.Configure<EventLogSettings>(settings =>
{
settings.SourceName = "My chosen name";
});