-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (58 loc) · 2.11 KB
/
Copy pathProgram.cs
File metadata and controls
68 lines (58 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Configuration;
using Signal9.Agent.Services;
using Signal9.Shared.Configuration;
using System.Text.Json;
var builder = Host.CreateApplicationBuilder(args);
// Add configuration with .NET 9 enhancements
builder.Configuration
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.AddUserSecrets<Program>(optional: true);
// Add enhanced logging with .NET 9 structured logging
builder.Services.AddLogging(logging =>
{
logging.ClearProviders();
logging.AddConsole();
// Add structured logging with .NET 9 improvements
logging.AddSimpleConsole(options =>
{
options.IncludeScopes = true;
options.SingleLine = true;
options.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] ";
});
});
// Add configuration options with validation
builder.Services.Configure<AgentConfiguration>(
builder.Configuration.GetSection("AgentConfiguration"));
// Add services with .NET 9 performance improvements
builder.Services.AddSingleton<ITelemetryCollector, TelemetryCollector>();
builder.Services.AddSingleton<ISystemInfoProvider, SystemInfoProvider>();
builder.Services.AddHostedService<AgentService>();
// Add HttpClient with .NET 9 optimizations
builder.Services.AddHttpClient("Signal9Api", client =>
{
client.BaseAddress = new Uri(builder.Configuration["Signal9Api:BaseUrl"] ?? "https://api.signal9.com");
client.Timeout = TimeSpan.FromSeconds(30);
});
var host = builder.Build();
// Create logger for startup
var logger = host.Services.GetRequiredService<ILogger<Program>>();
logger.LogInformation("Signal9 Agent starting up with .NET 9 optimizations");
try
{
await host.RunAsync();
}
catch (Exception ex)
{
logger.LogCritical(ex, "Application terminated unexpectedly");
throw;
}
finally
{
logger.LogInformation("Signal9 Agent shutting down");
await host.StopAsync();
}