Skip to content

Latest commit

 

History

History
47 lines (42 loc) · 1.41 KB

File metadata and controls

47 lines (42 loc) · 1.41 KB

Express-Notification-Service-Template

Enable Console out only while Debugging

console out on a Windows Service can create errors espcly while using ColorfulConsole

var hasConsoleOut = configuration.GetSection("EnableConsoleOut").Get<bool>();
if(hasConsoleOut)
{
     Console.Clear();
     ConsoleHeader();
     ConsoleInfo();
     QueueList();
}

To Run As A Windows Service

Install these nuGet libraries

Microsoft.Extensions.Hosting
Microsoft.Extensions.Hosting.WindowsServices

Add UseWindowsService(); on program.cs

Host.CreateDefaultBuilder(args)
     .UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration.ReadFrom.Configuration(hostingContext.Configuration))
     .ConfigureServices((hostContext, services) =>
     {
         services.AddHostedService<Worker>();
         services.AddSingleton<IMessagingQueue, MessagingQueue>();
         services.AddSingleton<IConsoleDataProvider, ConsoleDataProvider>();
     }).UseWindowsService();

Now Release Mode => Build

Powershell To Install Service

Open powershell and execute the command to install service on Windows Machines

sc.exe create <NameOfService> binpath= C:\test\service.exe start= auto

Powershell To UnInstall Service

Open powershell and execute the command to install service on Windows Machines

STOP Service first & execute the command

sc.exe delete <NameOfService>