Skip to content

Commit ff220fe

Browse files
(#11) Update docs
1 parent b4cecd0 commit ff220fe

File tree

3 files changed

+35
-13
lines changed

3 files changed

+35
-13
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,40 @@ builder.AddSqlServer(opts =>
5454
});
5555
```
5656

57+
### Adding logging
5758

59+
The configuration provider is set up too early in the pipeline to be able to accept logging from the start. However you can attach a logger after it has been set up. The configuration provider will also hold on to any log messages and replay them once a logger it attached. It works like this:
60+
61+
* When calling `AddSqlServer` on the configuration builder. Make sure you call `ExpectLogger()`. This sets up the replay mechanism.
62+
* Then set up your loggers. The SqlServerConfigurationProvider logs from Debug up.
63+
* By the time you get to configure services, you should be able to get a `ILoggerFactory`. There is an extension method, `AttachLoggerToSqlServerProvider` on `IConfigurationRoot` that will attach the logger.
64+
65+
```csharp
66+
await Host.CreateDefaultBuilder(args)
67+
.ConfigureAppConfiguration(builder =>
68+
{
69+
builder.AddSqlServer(opts =>
70+
{
71+
opts.FromExistingConfiguration()
72+
.ExpectLogger();
73+
});
74+
})
75+
.ConfigureLogging(builder =>
76+
{
77+
builder.AddConsole();
78+
builder.AddDebug();
79+
builder.SetMinimumLevel(LogLevel.Debug);
80+
})
81+
.ConfigureServices((ctx, services) =>
82+
{
83+
// Attach the logger to the SQL Server Configuration Provider
84+
IConfigurationRoot configRoot = (IConfigurationRoot) ctx.Configuration;
85+
configRoot.AttachLoggerToSqlServerProvider(services.BuildServiceProvider().GetService<ILoggerFactory>());
86+
})
87+
88+
```
89+
90+
CAUTION: If you call `ExpectLogger` and never attach a logger, it will just hold on to the log messages for the lifetime of the application in memory.
5891

5992
## Contributing / Getting Started
6093

release-notes/wip-release-notes.md

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,9 @@
44

55
Date: ???
66

7-
### Bugs
8-
97
### Features
108

11-
### Miscellaneous
12-
13-
### Dependent Packages
14-
15-
- .NET 5.0
16-
- No changes
17-
- .NET Core 3.1
18-
- No changes
19-
- General
20-
- No changes
9+
- #11: Add logging
2110

2211
---
2312

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.1
1+
0.2.0

0 commit comments

Comments
 (0)