Skip to content

Commit 45c66f3

Browse files
Update list-users example to show how to inject logger
1 parent da52cac commit 45c66f3

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

examples/list-users/Program.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
using System;
2+
using System.IO;
23
using System.Linq;
34
using System.Threading.Tasks;
5+
using Microsoft.Extensions.Configuration;
6+
using Microsoft.Extensions.Logging;
47
using Notion.Client;
58

69
namespace list_users
@@ -14,6 +17,19 @@ static async Task Main(string[] args)
1417
AuthToken = "<Token>"
1518
});
1619

20+
var configuration = new ConfigurationBuilder()
21+
.AddJsonFile(Directory.GetCurrentDirectory() + "/appsettings.json")
22+
.Build();
23+
24+
var factory = LoggerFactory.Create(builder =>
25+
{
26+
builder.ClearProviders();
27+
builder.AddConfiguration(configuration.GetSection("Logging"));
28+
builder.AddConsole();
29+
});
30+
31+
NotionLogging.ConfigureLogger(factory);
32+
1733
var usersList = await client.Users.ListAsync();
1834

1935
Console.WriteLine(usersList.Results.Count());
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information"
5+
}
6+
}
7+
}
Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
3-
<PropertyGroup>
4-
<OutputType>Exe</OutputType>
5-
<TargetFramework>net5.0</TargetFramework>
6-
<RootNamespace>list_users</RootNamespace>
7-
</PropertyGroup>
8-
9-
<ItemGroup>
10-
<PackageReference Include="Notion.Net" Version="1.0.4"/>
11-
</ItemGroup>
12-
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<RootNamespace>list_users</RootNamespace>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<!-- <PackageReference Include="Notion.Net" Version="1.0.4"/> -->
9+
<ProjectReference Include="..\..\Src\Notion.Client\Notion.Client.csproj"/>
10+
</ItemGroup>
11+
<ItemGroup>
12+
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0"/>
13+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0"/>
14+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0"/>
15+
</ItemGroup>
1316
</Project>

0 commit comments

Comments
 (0)