WindowsServiceLifetimeHostBuilderExtensions.AddWindowsService Method

Definition

Overloads

AddWindowsService(IServiceCollection)

Configures the lifetime of the IHost built from services to WindowsServiceLifetime and enables logging to the event log with the application name as the default source name.

AddWindowsService(IServiceCollection, Action<WindowsServiceLifetimeOptions>)

Configures the lifetime of the IHost built from services to WindowsServiceLifetime and enables logging to the event log with the application name as the default source name.

AddWindowsService(IServiceCollection)

Source:
WindowsServiceLifetimeHostBuilderExtensions.cs
Source:
WindowsServiceLifetimeHostBuilderExtensions.cs
Source:
WindowsServiceLifetimeHostBuilderExtensions.cs

Configures the lifetime of the IHost built from services to WindowsServiceLifetime and enables logging to the event log with the application name as the default source name.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddWindowsService(this Microsoft.Extensions.DependencyInjection.IServiceCollection services);

Parameters

Returns

The services instance for chaining.

Remarks

This is context aware and will only activate if it detects the process is running as a Windows Service.

Applies to

.NET 10 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)

AddWindowsService(IServiceCollection, Action<WindowsServiceLifetimeOptions>)

Source:
WindowsServiceLifetimeHostBuilderExtensions.cs
Source:
WindowsServiceLifetimeHostBuilderExtensions.cs
Source:
WindowsServiceLifetimeHostBuilderExtensions.cs

Configures the lifetime of the IHost built from services to WindowsServiceLifetime and enables logging to the event log with the application name as the default source name.

C#
public static Microsoft.Extensions.DependencyInjection.IServiceCollection AddWindowsService(this Microsoft.Extensions.DependencyInjection.IServiceCollection services, Action<Microsoft.Extensions.Hosting.WindowsServiceLifetimeOptions> configure);

Parameters

Returns

The services instance for chaining.

Remarks

This is context aware and will only activate if it detects the process is running as a Windows Service.

Applies to

.NET 10 (package-provided) dan versi lain
Produk Versi
.NET 8 (package-provided), 9 (package-provided), 10 (package-provided)
.NET Standard 2.0 (package-provided), 2.1 (package-provided)