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 1
1
// <setup>
2
2
using Microsoft . Extensions . DependencyInjection ;
3
3
using Microsoft . Extensions . Diagnostics . ResourceMonitoring ;
4
+ using Microsoft . Extensions . Hosting ;
4
5
using Microsoft . Extensions . Logging ;
5
6
using Spectre . Console ;
6
7
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 ( ) ;
12
15
13
- var monitor = provider . GetRequiredService < IResourceMonitor > ( ) ;
16
+ var monitor = app . Services . GetRequiredService < IResourceMonitor > ( ) ;
17
+ await app . StartAsync ( ) ;
14
18
// </setup>
15
19
16
20
using 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" >
2
2
3
3
<PropertyGroup >
4
4
<OutputType >Exe</OutputType >
11
11
<PackageReference Include =" Microsoft.Extensions.Logging.Console" Version =" 9.0.6" />
12
12
<PackageReference Include =" Microsoft.Extensions.DependencyInjection" Version =" 9.0.6" />
13
13
<PackageReference Include =" Microsoft.Extensions.Diagnostics.ResourceMonitoring" Version =" 9.6.0" />
14
+ <PackageReference Include =" Microsoft.Extensions.Hosting" Version =" 9.0.6" />
14
15
<PackageReference Include =" Spectre.Console" Version =" 0.50.0" />
15
16
</ItemGroup >
16
17
You can’t perform that action at this time.
0 commit comments