File tree Expand file tree Collapse file tree 3 files changed +12
-7
lines changed
snippets/resource-monitoring Expand file tree Collapse file tree 3 files changed +12
-7
lines changed Original file line number Diff line number Diff line change 11// <setup>
22using Microsoft . Extensions . DependencyInjection ;
33using Microsoft . Extensions . Diagnostics . ResourceMonitoring ;
4+ using Microsoft . Extensions . Hosting ;
45using Microsoft . Extensions . Logging ;
56using Spectre . Console ;
67
7- var services = new ServiceCollection ( )
8- . AddLogging ( static builder => builder . AddConsole ( ) )
9- . AddResourceMonitoring ( ) ;
10-
11- var provider = services . BuildServiceProvider ( ) ;
8+ var app = Host . CreateDefaultBuilder ( )
9+ . ConfigureServices ( services =>
10+ {
11+ services . AddLogging ( static builder => builder . AddConsole ( ) )
12+ . AddResourceMonitoring ( ) ;
13+ } )
14+ . Build ( ) ;
1215
13- var monitor = provider . GetRequiredService < IResourceMonitor > ( ) ;
16+ var monitor = app . Services . GetRequiredService < IResourceMonitor > ( ) ;
17+ await app . StartAsync ( ) ;
1418// </setup>
1519
1620using var cancellationTokenSource = new CancellationTokenSource ( ) ;
Original file line number Diff line number Diff line change 1- <Project Sdk =" Microsoft.NET.Sdk" >
1+ <Project Sdk =" Microsoft.NET.Sdk" >
22
33 <PropertyGroup >
44 <OutputType >Exe</OutputType >
1111 <PackageReference Include =" Microsoft.Extensions.Logging.Console" Version =" 9.0.6" />
1212 <PackageReference Include =" Microsoft.Extensions.DependencyInjection" Version =" 9.0.6" />
1313 <PackageReference Include =" Microsoft.Extensions.Diagnostics.ResourceMonitoring" Version =" 9.6.0" />
14+ <PackageReference Include =" Microsoft.Extensions.Hosting" Version =" 9.0.6" />
1415 <PackageReference Include =" Spectre.Console" Version =" 0.50.0" />
1516 </ItemGroup >
1617
You can’t perform that action at this time.
0 commit comments