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();
}
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();
Open powershell and execute the command to install service on Windows Machines
sc.exe create <NameOfService> binpath= C:\test\service.exe start= auto
Open powershell and execute the command to install service on Windows Machines
STOP Service first & execute the command
sc.exe delete <NameOfService>