internal static DiagnosticListener LogHostBuilding(HostApplicationBuilder hostApplicationBuilder) { var diagnosticListener = new DiagnosticListener(HostBuildingDiagnosticListenerName); if (diagnosticListener.IsEnabled() && diagnosticListener.IsEnabled(HostBuildingEventName)) { Write(diagnosticListener, HostBuildingEventName, hostApplicationBuilder.AsHostBuilder()); } return(diagnosticListener); }
public void ServiceCollectionExtensionMethodAddsWindowsServiceLifetimeInsideOfService() { var builder = new HostApplicationBuilder(); // Emulate calling builder.Services.AddWindowsService() from inside a Windows service. AddWindowsServiceLifetime(builder.Services); Assert.Single(builder.Services, serviceDescriptor => serviceDescriptor.ServiceType == typeof(IHostLifetime) && serviceDescriptor.ImplementationType == typeof(WindowsServiceLifetime)); }
public void ServiceCollectionExtensionMethodDefaultsToOffOutsideOfService() { var builder = new HostApplicationBuilder(); builder.Services.AddWindowsService(); // No reason to write event logs in this test. Event log may be unsupported anyway. builder.Logging.ClearProviders(); using IHost host = builder.Build(); var lifetime = host.Services.GetRequiredService <IHostLifetime>(); Assert.IsType <ConsoleLifetime>(lifetime); }
public void ServiceCollectionExtensionMethodCanBeCalledOnDefaultConfiguration() { var builder = new HostApplicationBuilder(); // Emulate calling builder.Services.AddWindowsService() from inside a Windows service. AddWindowsServiceLifetime(builder.Services); // No reason to write event logs in this test. builder.Logging.ClearProviders(); using IHost host = builder.Build(); var lifetime = host.Services.GetRequiredService <IHostLifetime>(); Assert.IsType <WindowsServiceLifetime>(lifetime); }
public void ServiceCollectionExtensionMethodDefaultsToOffOutsideOfService() { var builder = new HostApplicationBuilder(new HostApplicationBuilderSettings { // Disable defaults that may not be supported on the testing platform like EventLogLoggerProvider. DisableDefaults = true, }); builder.Services.AddSystemd(); using IHost host = builder.Build(); var lifetime = host.Services.GetRequiredService <IHostLifetime>(); Assert.NotNull(lifetime); Assert.IsNotType <SystemdLifetime>(lifetime); }
public void ServiceCollectionExtensionMethodSetsEventLogSourceNameToApplicationNameInsideOfService() { string appName = Guid.NewGuid().ToString(); var builder = new HostApplicationBuilder(new HostApplicationBuilderSettings { ApplicationName = appName, }); // Emulate calling builder.Services.AddWindowsService() from inside a Windows service. AddWindowsServiceLifetime(builder.Services); // No reason to write event logs in this test. builder.Logging.ClearProviders(); using IHost host = builder.Build(); var eventLogSettings = host.Services.GetRequiredService <IOptions <EventLogSettings> >().Value; Assert.Same(appName, eventLogSettings.SourceName); }