Add start-service.bat script for Resource Monitor Service v2.0
- Introduced a batch script to simplify the startup process for the Resource Monitor Service. - Included checks for .NET 9.0 Runtime installation. - Added build and run commands for the service with appropriate error handling. - Provided user instructions and API documentation links in the script output.
This commit is contained in:
+44
-2
@@ -1,5 +1,9 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using ResourceMonitorService.Configuration;
|
||||
using ResourceMonitorService.Services;
|
||||
using Serilog;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ResourceMonitorService
|
||||
@@ -8,20 +12,58 @@ namespace ResourceMonitorService
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
// Configure Serilog early
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/resourcemonitor-.txt", rollingInterval: RollingInterval.Day)
|
||||
.CreateLogger();
|
||||
|
||||
try
|
||||
{
|
||||
Log.Information("Starting Resource Monitor Service");
|
||||
CreateHostBuilder(args).Build().Run();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Fatal(ex, "Application start-up failed");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Log.CloseAndFlush();
|
||||
}
|
||||
}
|
||||
|
||||
public static IHostBuilder CreateHostBuilder(string[] args)
|
||||
{
|
||||
var builder = Host.CreateDefaultBuilder(args)
|
||||
.UseSerilog()
|
||||
.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
// Bind configuration sections
|
||||
services.Configure<MonitoringSettings>(
|
||||
hostContext.Configuration.GetSection("MonitoringSettings"));
|
||||
services.Configure<ApiSettings>(
|
||||
hostContext.Configuration.GetSection("ApiSettings"));
|
||||
services.Configure<LoggingSettings>(
|
||||
hostContext.Configuration.GetSection("LoggingSettings"));
|
||||
|
||||
// Register services
|
||||
services.AddSingleton<ISystemInfoService, SystemInfoService>();
|
||||
services.AddSingleton<IResourceMonitorService, Services.ResourceMonitorService>();
|
||||
services.AddSingleton<IGameDetectionService, GameDetectionService>();
|
||||
services.AddSingleton<IAlertService, AlertService>();
|
||||
|
||||
// Register the main worker service
|
||||
services.AddHostedService<Worker>();
|
||||
});
|
||||
|
||||
// Configure as Windows Service if requested
|
||||
if (args.Contains("--windows-service") || Environment.GetEnvironmentVariable("RUN_AS_SERVICE") == "true")
|
||||
{
|
||||
builder.UseWindowsService();
|
||||
builder.UseWindowsService(options =>
|
||||
{
|
||||
options.ServiceName = "ResourceMonitorService";
|
||||
});
|
||||
}
|
||||
|
||||
return builder;
|
||||
|
||||
Reference in New Issue
Block a user