Skip to content

Commit 82c1446

Browse files
Merge pull request #173 from Stravaig-Projects/#123/create-logger-of-t
#123: Add TestCaptureLoggerProvider.CreateLogger()
2 parents fffeb5e + 4dd1ba9 commit 82c1446

22 files changed

+609
-265
lines changed

.github/PULL_REQUEST_TEMPLATE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ If any of these items are not needed, then they can be removed.
2929
-->
3030

3131
- [ ] I have updated the `readme.md` file
32+
- [ ] I have updated the documentation in the docs folder.
3233
- [ ] I have bumped the version number in the `version.txt`
3334
- [ ] I have added or updated any necessary tests.
3435
- [ ] I have ensured that any new code is covered by tests where reasonably possible.

docs/contributors.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ title: Contributors
77

88
This is a list of all the contributors to this repository in ascending order by the contributor name.
99

10-
**Colin Mackay** contributed 296 commits from Saturday, 26 September, 2020 @ 20:26:19 +00:00 to Sunday, 30 July, 2023 @ 19:26:52 +00:00.
10+
**Colin Mackay** contributed 331 commits from Saturday, 26 September, 2020 @ 21:26:19 +01:00 to Tuesday, 27 February, 2024 @ 21:43:15 +00:00.
1111

12-
**dependabot[bot]** contributed 50 commits from Wednesday, 14 October, 2020 @ 19:13:43 +00:00 to Tuesday, 27 June, 2023 @ 14:56:42 +00:00.
12+
**dependabot[bot]** contributed 59 commits from Wednesday, 14 October, 2020 @ 20:13:43 +01:00 to Monday, 26 February, 2024 @ 14:54:09 +00:00.
1313

14-
**StravaigBot** contributed 25 commits from Monday, 14 December, 2020 @ 19:28:09 +00:00 to Tuesday, 13 June, 2023 @ 21:19:26 +00:00.
14+
**StravaigBot** contributed 27 commits from Monday, 14 December, 2020 @ 19:28:09 +00:00 to Wednesday, 15 November, 2023 @ 14:09:41 +00:00.
1515

1616
## Summary
1717

18-
* 371 commits in total.
18+
* 417 commits in total.
1919

20-
* From Saturday, 26 September, 2020 @ 20:26:19 +00:00.
20+
* From Saturday, 26 September, 2020 @ 21:26:19 +01:00.
2121

22-
* Until Sunday, 30 July, 2023 @ 19:26:52 +00:00.
22+
* Until Tuesday, 27 February, 2024 @ 21:43:15 +00:00.
2323

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
layout: default
3+
title: ITestCaptureLogger interface
4+
---
5+
6+
# ITestCaptureLogger
7+
8+
**Available from v3.0**
9+
10+
This interface is implemented by:
11+
* `TestCaptureLogger` (see: [TestCaptureLogger](test-capture-logger.md))
12+
* `TestCaptureLogger<T>` (see: [TestCaptureLogger&lt;T>](test-capture-logger-of-t.md))
13+
14+
# ITestCaptureLogger methods
15+
16+
## GetLogs()
17+
18+
The `ITestCaptureLogger.GetLogs()` method allows you to retrieve the logs within your test method. The property will be in sequence, timestamps will be incremental, however adjacent log entries created sufficiently close to one another may contain the same timestamp due to the resolution of the clock.
19+
20+
#### Returns
21+
22+
`IReadOnlyList<LogEntry>`: A read only list of log entries. See [LogEntry](log-entry.md)
23+
24+
##### Remarks
25+
26+
The result of the method can be passed into `RenderLogs()` extension method. See [Renderer](log-entry-renderer-extensions.md)
27+
28+
29+
---
30+
## GetLogEntriesWithExceptions()
31+
32+
The `ITestCaptureLogger.GetLogEntriesWithExceptions()` method gets all the log entries generated via this logger in sequential order that have exception objects attached to them.
33+
34+
```csharp
35+
// Arrange
36+
var logger = new TestCaptureLogger();
37+
38+
// Act: Do something using the logger
39+
40+
// Assert
41+
var logs = logger.GetAllLogEntriesWithExceptions();
42+
// logs is a read only list of LogEntry objects in sequential order.
43+
```
44+
45+
#### Returns
46+
47+
`IReadOnlyList<LogEntry>`: A read only list of log entries. See [LogEntry](log-entry.md)
48+
49+
##### Remarks
50+
51+
The result of the method can be passed into `RenderLogs()` extension method. See [Renderer](log-entry-renderer-extensions.md)
52+
53+
---
54+
## Reset()
55+
56+
Clears all the logs in the Logger.
57+
58+
If you reuse the same logger in multiple tests, be careful that the tests do not run in parallel with one another.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
layout: default
3+
title: TestCaptureLogger&lt;T> class
4+
---
5+
6+
# TestCaptureLogger&lt;T>
7+
8+
**In V1 & V2 this class inherits from `TestCaptureLogger`. From V3 this class implements the interface `ITestCaptureLogger`.**
9+
10+
This class implements
11+
* `ITestCaptureLogger` (See: [ITestCaptureLogger interface](i-test-capture-logger-interface.md))
12+
* `ILogger<T>`
13+
14+
# ITestCaptureLogger methods
15+
16+
## GetLogs()
17+
18+
The `ITestCaptureLogger.GetLogs()` method allows you to retrieve the logs within your test method. The property will be in sequence, timestamps will be incremental, however adjacent log entries created sufficiently close to one another may contain the same timestamp due to the resolution of the clock.
19+
20+
#### Returns
21+
22+
`IReadOnlyList<LogEntry>`: A read only list of log entries. See [LogEntry](log-entry.md)
23+
24+
##### Remarks
25+
26+
The result of the method can be passed into `RenderLogs()` extension method. See [Renderer](log-entry-renderer-extensions.md)
27+
28+
29+
---
30+
## GetLogEntriesWithExceptions()
31+
32+
The `ITestCaptureLogger.GetLogEntriesWithExceptions()` method gets all the log entries generated via this logger in sequential order that have exception objects attached to them.
33+
34+
```csharp
35+
// Arrange
36+
var logger = new TestCaptureLogger<MyService>();
37+
38+
// Act: Do something using the logger
39+
40+
// Assert
41+
var logs = logger.GetAllLogEntriesWithExceptions();
42+
// logs is a read only list of LogEntry objects in sequential order.
43+
```
44+
45+
#### Returns
46+
47+
`IReadOnlyList<LogEntry>`: A read only list of log entries. See [LogEntry](log-entry.md)
48+
49+
##### Remarks
50+
51+
The result of the method can be passed into `RenderLogs()` extension method. See [Renderer](log-entry-renderer-extensions.md)
52+
53+
---
54+
## Reset()
55+
56+
Clears all the logs in the Logger.
57+
58+
If you reuse the same logger in multiple tests, be careful that the tests do not run in parallel with one another.

docs/docs/library/test-capture-logger-provider.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ title: TestCaptureLoggerProvider class
77

88
The provider passed to the logging framework.
99

10+
This class implements
11+
* `ICapturedLogs`
12+
* `ILoggingProvider`
13+
14+
## CreateLogger&lt;T>
15+
16+
Creates or returns an exsting `TestCaptureLogger<T>`. This is a generic alternative to the non-generic version from `ILoggerProvider`.
17+
1018
## GetCategories()
1119

1220
Gets all the logger categories created by this provider. NOTE: There is the possibility that the category may not contain any logs.

docs/docs/library/test-capture-logger.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ layout: default
33
title: TestCaptureLogger class
44
---
55

6+
# TestCaptureLogger
7+
8+
This class implements
9+
* `ITestCaptureLogger` (See: [ITestCaptureLogger interface](i-test-capture-logger-interface.md))
10+
* `ILogger`
11+
612
# TestCaptureLogger methods
713

814
## GetLogs()

docs/index.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ This package is designed to hook into the .NET logging framework so that the log
2222
## Scenarios
2323

2424
* [Injecting a logger to the class under test](docs/scenarios/inject-logger-to-class-under-test.md)
25-
* [Injecing a logger factory to the class under test](docs/scenarios/inject-logger-factory-to-class-under-test.md)
25+
* [Injecting a logger factory to the class under test](docs/scenarios/inject-logger-factory-to-class-under-test.md)
2626
* [Using a WebApplicationFactory](docs/scenarios/using-a-web-application-factory.md)
2727

2828
## Library
2929

30+
* [ITestCaptureLogger](docs/library/i-test-capture-logger-interface.md)
3031
* [LogEntry](docs/library/log-entry.md)
3132
* [TestCaptureLogger](docs/library/test-capture-logger.md)
33+
* [TestCaptureLogger&lt;T>](docs/library/test-capture-logger-of-t.md)
3234
* [TestCaptureLoggerProvider](docs/library/test-capture-logger-provider.md)
3335

3436
#### Extensions
@@ -49,9 +51,9 @@ This package is designed to hook into the .NET logging framework so that the log
4951

5052
## Supported .NET Versions
5153

52-
Current version supports: 6.0, 7.0 and 8.0
54+
v2.x supports: .NET 6.0, 7.0 and 8.0
5355

54-
.NET Core 3.1 and .NET 5.0 support was dropped as of v2.0. Use v1.x when targeting .NET Core 3.1 or .NET 5.0.
56+
v1.z supports: .NET Core 3.1 and .NET 5.0
5557

5658
## Other Stuff
5759

docs/release-notes/index.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ title: Release Notes
77

88
The releases on this package most recent first.
99

10+
- **[v2.2.1](release-notes-2.2.1.md) released on Tuesday, 27 February, 2024 at 21:50:08 +00:00**
11+
- [GitHub Release](https://github.com/Stravaig-Projects/Stravaig.Extensions.Logging.Diagnostics/releases/tag/v2.2.1)
12+
- **[v2.2.0](release-notes-2.2.0.md) released on Wednesday, 15 November, 2023 at 14:09:34 +00:00**
13+
- [GitHub Release](https://github.com/Stravaig-Projects/Stravaig.Extensions.Logging.Diagnostics/releases/tag/v2.2.0)
14+
- **[v2.1.0](release-notes-2.1.0.md) released on Monday, 31 July, 2023 at 23:49:18 +01:00**
15+
- [GitHub Release](https://github.com/Stravaig-Projects/Stravaig.Extensions.Logging.Diagnostics/releases/tag/v2.1.0)
1016
- **[v2.0.1](release-notes-2.0.1.md) released on Tuesday, 13 June, 2023 at 22:19:18 +01:00**
1117
- [GitHub Release](https://github.com/Stravaig-Projects/Stravaig.Extensions.Logging.Diagnostics/releases/tag/v2.0.1)
1218
- **[v2.0.0](release-notes-2.0.0.md) released on Saturday, 11 February, 2023 at 23:00:02 +00:00**

release-notes/wip-release-notes.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,18 @@
44

55
Date: ???
66

7+
### Breaking Changes
8+
9+
- Feature #123 changes the `TestCaptureLogger<T>` class to encapsulate an instance of `TestCaptureLogger` rather than inherit from it. If you're code relied on `TestCaptureLogger<T>` inheriting from `TestCaptureLogger` then it will likely break.
10+
711
### Bugs
812

913
### Features
1014

15+
- #123: `TestCaptureLoggerProvider.CreateLogger<T>()`
16+
- Potential breaking change: `TestCaptureLogger<T>` no longer inherits from `TestCaptureLogger`.
17+
- Add `ITestCaptureLogger` and have `TestCaptureLogger` and `TestCaptureLogger<T>` be concrete implementations of the interface so you can reference the interface and not care which concrete implementation you have.
18+
1119
### Miscellaneous
1220

1321
- #164: Update pipeline.
@@ -17,6 +25,3 @@ Date: ???
1725
- #166 Update package references:
1826
- .NET 8.0 targets:
1927
- Bump Microsoft.Extensions.Logging.Abstractions to 8.0.1
20-
21-
22-

src/.idea/.idea.Stravaig.Extensions.Logging.Diagnostics/.idea/projectSettingsUpdater.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)