|
4 | 4 | using Microsoft.Extensions.Configuration; |
5 | 5 | using Signal9.Agent.Services; |
6 | 6 | using Signal9.Shared.Configuration; |
| 7 | +using System.Text.Json; |
7 | 8 |
|
8 | 9 | var builder = Host.CreateApplicationBuilder(args); |
9 | 10 |
|
10 | | -// Add configuration |
| 11 | +// Add configuration with .NET 9 enhancements |
11 | 12 | builder.Configuration |
12 | 13 | .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) |
13 | 14 | .AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true) |
14 | | - .AddEnvironmentVariables(); |
| 15 | + .AddEnvironmentVariables() |
| 16 | + .AddUserSecrets<Program>(optional: true); |
15 | 17 |
|
16 | | -// Add logging |
| 18 | +// Add enhanced logging with .NET 9 structured logging |
17 | 19 | builder.Services.AddLogging(logging => |
18 | 20 | { |
19 | 21 | logging.ClearProviders(); |
20 | 22 | logging.AddConsole(); |
21 | | - if (OperatingSystem.IsWindows()) |
| 23 | + |
| 24 | + // Add structured logging with .NET 9 improvements |
| 25 | + logging.AddSimpleConsole(options => |
22 | 26 | { |
23 | | - logging.AddEventLog(); |
24 | | - } |
| 27 | + options.IncludeScopes = true; |
| 28 | + options.SingleLine = true; |
| 29 | + options.TimestampFormat = "[yyyy-MM-dd HH:mm:ss] "; |
| 30 | + }); |
25 | 31 | }); |
26 | 32 |
|
27 | | -// Add configuration options |
| 33 | +// Add configuration options with validation |
28 | 34 | builder.Services.Configure<AgentConfiguration>( |
29 | 35 | builder.Configuration.GetSection("AgentConfiguration")); |
30 | 36 |
|
31 | | -// Add services |
| 37 | +// Add services with .NET 9 performance improvements |
32 | 38 | builder.Services.AddSingleton<ITelemetryCollector, TelemetryCollector>(); |
33 | 39 | builder.Services.AddSingleton<ISystemInfoProvider, SystemInfoProvider>(); |
34 | 40 | builder.Services.AddHostedService<AgentService>(); |
35 | 41 |
|
| 42 | +// Add HttpClient with .NET 9 optimizations |
| 43 | +builder.Services.AddHttpClient("Signal9Api", client => |
| 44 | +{ |
| 45 | + client.BaseAddress = new Uri(builder.Configuration["Signal9Api:BaseUrl"] ?? "https://api.signal9.com"); |
| 46 | + client.Timeout = TimeSpan.FromSeconds(30); |
| 47 | +}); |
| 48 | + |
36 | 49 | var host = builder.Build(); |
37 | 50 |
|
38 | 51 | // Create logger for startup |
39 | 52 | var logger = host.Services.GetRequiredService<ILogger<Program>>(); |
40 | | -logger.LogInformation("Signal9 Agent starting up"); |
| 53 | +logger.LogInformation("Signal9 Agent starting up with .NET 9 optimizations"); |
41 | 54 |
|
42 | 55 | try |
43 | 56 | { |
|
51 | 64 | finally |
52 | 65 | { |
53 | 66 | logger.LogInformation("Signal9 Agent shutting down"); |
| 67 | + await host.StopAsync(); |
54 | 68 | } |
0 commit comments