Skip to content

Commit 7c989f9

Browse files
Add Windows Service support to the MassTransit Connector host (#343)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danielmarbach <174258+danielmarbach@users.noreply.github.com>
1 parent 88d0b4c commit 7c989f9

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/ServiceControl.Connector.MassTransit.Host/Commands/StartupCommand.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ namespace ServiceControl.Connector.MassTransit.Host.Commands;
33
using System.CommandLine;
44
using Microsoft.Extensions.DependencyInjection;
55
using Microsoft.Extensions.Hosting;
6+
using Microsoft.Extensions.Hosting.WindowsServices;
67
using Microsoft.Extensions.Logging;
78
using NServiceBus.Extensions.Logging;
89
using ServiceControl.Connector.MassTransit;
@@ -43,6 +44,9 @@ async Task<int> InternalHandler(RunMode runMode, bool isConsole, string[] connec
4344
var builder = Host.CreateApplicationBuilder(connectorArgs);
4445
builder.UseMassTransitConnector(runMode == RunMode.Setup);
4546

47+
// Registers WindowsServiceLifetime and EventLog logging when running as a Windows Service; no-op otherwise.
48+
builder.Services.AddWindowsService();
49+
4650
if (isConsole)
4751
{
4852
builder.Logging.AddSimpleConsole(o =>
@@ -51,7 +55,7 @@ async Task<int> InternalHandler(RunMode runMode, bool isConsole, string[] connec
5155
o.IncludeScopes = true;
5256
});
5357
}
54-
else
58+
else if (!WindowsServiceHelpers.IsWindowsService())
5559
{
5660
builder.Logging.AddSystemdConsole();
5761
}

src/ServiceControl.Connector.MassTransit.Host/ServiceControl.Connector.MassTransit.Host.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
<ItemGroup>
1717
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.14" />
18+
<PackageReference Include="Microsoft.Extensions.Hosting.WindowsServices" Version="9.0.14" />
1819
<PackageReference Include="Microsoft.Extensions.Options.DataAnnotations" Version="9.0.14" />
1920
<PackageReference Include="NServiceBus.Extensions.Logging" Version="3.0.1" />
2021
<PackageReference Include="System.CommandLine" Version="2.0.4" />

0 commit comments

Comments
 (0)