d6efa9163b
- Implemented ITelegramNotificationService and TelegramNotificationService for sending alerts via Telegram. - Updated MonitoringSettings to include Telegram configuration options. - Enhanced AlertService to send alerts and resolutions through Telegram. - Added API endpoints for checking Telegram status and sending test alerts. - Updated README and TELEGRAM_SETUP.md with setup instructions and features. - Included example configuration in appsettings.telegram.example.json.
73 lines
2.7 KiB
C#
73 lines
2.7 KiB
C#
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
|
|
{
|
|
public class Program
|
|
{
|
|
public static void Main(string[] args)
|
|
{
|
|
// 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<ITelegramNotificationService, TelegramNotificationService>();
|
|
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(options =>
|
|
{
|
|
options.ServiceName = "ResourceMonitorService";
|
|
});
|
|
}
|
|
|
|
return builder;
|
|
}
|
|
}
|
|
} |